package com.htjc.integral.account.service.impl;

/**
 * 账户中心的业务层实现类
 * 1、所有方法做好日志记录、和注释
 */
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.htjc.integral.account.mapper.newdb.EcBpAccountIntegralDetailMapper;
import com.htjc.integral.account.mapper.newdb.EcBpAccountIntegralMapper;
import com.htjc.integral.account.mapper.newdb.EcBpAssethubIntegralMapper;
import com.htjc.integral.account.mapper.newdb.EcBpConsNoIntegralMapper;
import com.htjc.integral.account.mapper.newdb.EcBpIncomeIntegralMapper;
import com.htjc.integral.account.mapper.newdb.EcBpTransferBindingMapper;
import com.htjc.integral.account.service.IAccountService;
import com.htjc.integral.account.service.InvokeBuildOuterService;
import com.htjc.integral.account.util.AtbashUtils;
import com.htjc.integral.account.util.DebAsetHttpUtil;
import com.htjc.integral.account.util.JsonUtil;
import com.htjc.integral.account.util.ResultModel;
import com.htjc.integral.account.util.UrlConfigUtil;
import com.htjc.integral.account.util.enums.AccountConstant;
import com.htjc.integral.account.util.enums.AccountReturn;
import com.htjc.integral.account.util.enums.NewAccountConstant;
import com.htjc.integral.account.util.enums.ProvinceCodeEnums;
import com.htjc.integral.account.util.enums.RedisKey;
import com.htjc.integral.common.util.RequestUtils;
import com.htjc.integral.common.util.StrUtil;
import com.htjc.integral.common.util.StringUtil;
import com.htjc.integral.common.util.TimeUtil;
import com.htjc.integral.common.util.UUIDGenerator;
import com.htjc.integral.common.util.UUIDUtil;
import com.htjc.integral.model.account.EcBpAssethubIntegral;
import com.htjc.integral.model.account.EcBpTransferBinding;
import com.htjc.integral.model.newaccount.EcBpAccountIntegral;
import com.htjc.integral.model.newaccount.EcBpAccountIntegralDetail;
import com.htjc.integral.model.newaccount.EcBpConsNoIntegral;
import com.htjc.integral.model.newaccount.EcBpInComeIntegral;

import lombok.extern.slf4j.Slf4j;

@Slf4j(topic = "jfLog")
@Service
public class AccountServiceImpl implements IAccountService {

	@Value("${spring.param.proportion}")
	private BigDecimal proportion;

	@Autowired
	private EcBpAssethubIntegralMapper ecBpAssethubIntegralMapper;

	@Autowired
	private UrlConfigUtil urlConfigUtil;

	@Autowired
	private EcBpTransferBindingMapper ecBpTransferBindingMapper;

	@Autowired
	private InvokeBuildOuterService invokeBuildOuterService;

	@Autowired
	private NewAccountServiceImpl newAccountServiceImpl;

	/** 积分收入表  */
	@Autowired
	private EcBpIncomeIntegralMapper incomeIntegralMapper;

	/** 积分户号账户表  */
	@Autowired
	private EcBpConsNoIntegralMapper consNoIntegralMapper;
	/** 积分账户总表  */
	@Autowired
	private EcBpAccountIntegralMapper accountIntegralMapper;

	/** 积分账户明细表  */
	@Autowired
	private EcBpAccountIntegralDetailMapper accountIntegralDetailMapper;
	//	@Autowired
	//	private EcBpMemberDetailMapper ecBpMemberDetailMapper;

	/**
	 * 交费用户积分划转
	 * 
	 * @param jsonObject() 注意： 1、用户缴费是多个户号需要处理
	 *        2、分布式是事务的处理，户号积分扣减成功，但是资产中心积分未增加，要怎么处理。
	 * 
	 *        建议： 1、生成订单、标记状态、跟踪好订单信息 2、异步处理
	 */
	@Override
	public JSONObject payChangeIntegral(JSONObject json) {
		JSONObject jsonObject = null;
		//户号接口地址
		String QUERY_URL = urlConfigUtil.getUrlByKey(RedisKey.URLCON_PREFIXX.getKey(), RedisKey.HOUSE_INTEGRAL_QUERY.getKey());
		String TRANSFER_URL = urlConfigUtil.getUrlByKey(RedisKey.URLCON_PREFIXX.getKey(), RedisKey.HOUSE_INTEGRAL_TRANSFER.getKey());
		try {
			List<Map<String, Object>> powerUserNoReturn = new ArrayList<Map<String, Object>>();
			// 1、解析参数
			String LOGIN_ID = json.getString("LOGIN_ID");// 登录账户ID
			String UN_ID = json.getString("UN_ID");// 统一用户ID
			String BUSINESS_ID = json.getString("ACCOUNT_MAIN_ID");// 业务ID
			String list = json.getString("LIST");// 循环域
			String poweruserlist = json.getString("POWERUSERNOLIST");// 绑定关系循环域
			JSONArray array = JSON.parseArray(list);// 缴费list
			JSONArray array1 = JSON.parseArray(poweruserlist);// 绑定关系list
			//双重遍历，获取每一个交费户号的绑定关系类型03强绑定  04未手动绑定/无绑定关系 00手动绑定 05高压用户不划转
			List<Map<String, String>> rlist=new ArrayList<Map<String, String>>();
			for (int i = 0; i < array.size(); i++) {
				Map<String, String> map=new HashMap<String, String>();
				String consNo=array.getJSONObject(i).getString("POWER_USER_NO");
				map.put("POWER_USER_NO", consNo);
				String status="04";//默认为无绑定关系
				//根据户号查询是否有强绑定关系
				List<EcBpTransferBinding> selectQBindingByConsNo = ecBpTransferBindingMapper.selectQBindingByConsNo(consNo);
				if(selectQBindingByConsNo!=null&&selectQBindingByConsNo.size()>0){
					status="03";
				}else{
					for (int j = 0; j < array1.size(); j++) {
						if(consNo.equals(array1.getJSONObject(j).getString("consNo_dst"))){
							if(AccountConstant.BINDING_HIGHB.equals(array1.getJSONObject(j).getString("elecTypeCode"))) {
								status="05";
							}else {
								status="00";
								map.put("ORG_NO", array.getJSONObject(i).getString("ORG_NO"));
								map.put("PROVINCE_CODE", array.getJSONObject(i).getString("PROVINCE_CODE"));
								map.put("PAY_NUM", array.getJSONObject(i).getString("PAY_NUM"));
							}
							//							if(AccountConstant.BINDING_SDBD.equals(array1.getJSONObject(j).getString("constType"))){
							//								status="00";
							//								map.put("ORG_NO", array.getJSONObject(i).getString("ORG_NO"));
							//								map.put("PROVINCE_CODE", array.getJSONObject(i).getString("PROVINCE_CODE"));
							//								map.put("PAY_NUM", array.getJSONObject(i).getString("PAY_NUM"));
							//							}else{
							//								status="03";
							//							}
						}
					}
				}
				map.put("STATUS", status);
				log.info(consNo+":"+status);
				rlist.add(map);
			}
			for (Map<String, String> map2 : rlist) {
				JSONObject returnJson = new JSONObject();
				String POWER_USER_NO=map2.get("POWER_USER_NO");//户号
				String status=map2.get("STATUS");//状态 03强绑定  04未手动绑定/无绑定关系 00手动绑定  05高压用户不划转
				returnJson.put("POWER_USER_NO", POWER_USER_NO);
				returnJson.put("CREATE_TIIME", new Date());
				if(status.equals("03")||status.equals("04")){
					returnJson.put("INTEGRAL_NUM", "0");
					returnJson.put("STATUS", status);
					returnJson.put("MESSAGE",status.equals("03")?"已有强绑定":"未手动绑定");
				}
				else if(status.equals("05")) {
					returnJson.put("INTEGRAL_NUM", "0");
					returnJson.put("STATUS", status);
					returnJson.put("MESSAGE","高压用户不划转");
				}
				else{
					log.info("【户号中心查询】URL：" + QUERY_URL);
					String ORG_NO =map2.get("ORG_NO");// 供电单位编号
					String PROVINCE_CODE = map2.get("PROVINCE_CODE");// 网省编号
					BigDecimal PAY_NUM = new BigDecimal(map2.get("PAY_NUM"));// 交费金额
					JSONObject object = new JSONObject();
					object.put("POWER_USER_NO", POWER_USER_NO);
					object.put("PROVINCE_CODE", PROVINCE_CODE);
					object.put("ORG_NO",ORG_NO);
					log.info("【户号中心查询】请求参数：" + object);
					String result = RequestUtils.sendPost(QUERY_URL, object.toString());
					log.info("【户号中心查询】返回参数：" + result);
					JSONObject balanceJson = JSONObject.parseObject(result);
					if (!"0".equals(balanceJson.getString("code"))) {
						returnJson.put("INTEGRAL_NUM", "0");
						returnJson.put("STATUS", "02");
						returnJson.put("MESSAGE","户号中心查询失败");
						powerUserNoReturn.add(returnJson);
						continue;
					}
					//用户的积分余额
					String content = balanceJson.getString("content");
					JSONObject jo = JSON.parseObject(content);
					BigDecimal Balance = jo.getBigDecimal("BALANCE");
					if("0".equals(Balance.compareTo(BigDecimal.ZERO))){
						returnJson.put("INTEGRAL_NUM", "0");
						returnJson.put("STATUS", "05");
						returnJson.put("MESSAGE","户号积分为0");
						powerUserNoReturn.add(returnJson);
						continue;
					}
					// 转化积分上限
					BigDecimal conversionIntegral = PAY_NUM.multiply(proportion);
					// 调用用户积分余额扣减,调用资产中心接口给账户增加积分
					BigDecimal deductionIntegral = new BigDecimal("0");
					// 如果扣减积分小于扣减上限,扣减扣减积分
					if (Balance.compareTo(conversionIntegral) <= 0) {
						deductionIntegral = Balance;
					} else {
						// 如果扣减积分大于扣减上限,扣减上限积分
						deductionIntegral = conversionIntegral;
					}
					log.info("转化积分比例："+proportion+"，转化积分上限："+conversionIntegral+"，转化积分："+deductionIntegral);
					returnJson.put("INTEGRAL_NUM", deductionIntegral.toString());
					//调用用户积分余额扣减接口
					String jsonDedConsBalanceResult=dedConsBalance(TRANSFER_URL, PROVINCE_CODE, ORG_NO, POWER_USER_NO,BUSINESS_ID, "01", "01", deductionIntegral.toString());
					JSONObject jsonDedCons=JSONObject.parseObject(jsonDedConsBalanceResult);
					if(!"0".equals(jsonDedCons.get("code").toString())) {
						returnJson.put("STATUS", "02");
						returnJson.put("MESSAGE","户号中心扣减失败");
						powerUserNoReturn.add(returnJson);
						continue;
					}
					//调用资产中心账号增加接口
					JSONObject addjson = new JSONObject();
					addjson.put("BUSINESS_ID",BUSINESS_ID);
					addjson.put("SOURCE_DESCRIBE", "交费用户积分划转");
					addjson.put("INCOME_NUM", deductionIntegral.toString());
					addjson.put("INCOME_SOURCE", "01");
					addjson.put("OPERATION_STATUS", "01");
					addjson.put("LOGIN_ACCOUNT_ID", UN_ID);
					addjson.put("USER_NAME", AtbashUtils.encrypt(json.getString("USER_NAME")));
					addjson.put("IP", json.getString("IP"));
					addjson.put("CHANNEL_RESOURCE", json.getString("CHANNEL_RESOURCE"));
					JSONObject accountServiceReturn = modifyIntegral(addjson, AccountConstant.AMT_DIRECTION_IN);
					if (!"01".equals(accountServiceReturn.get("resultCode").toString())) {
						returnJson.put("STATUS", "02");
						returnJson.put("MESSAGE","资产中心添加失败");
						powerUserNoReturn.add(returnJson);
						continue;
					}
					returnJson.put("STATUS", "01");
					returnJson.put("MESSAGE","交费积分划转成功");
				}
				powerUserNoReturn.add(returnJson);
			}
			JSONObject resultJson = new JSONObject();
			resultJson.put("ACCOUNT_MAIN_ID", BUSINESS_ID);
			resultJson.put("LOGIN_ID", LOGIN_ID);
			resultJson.put("UN_ID", UN_ID);
			//			resultJson.put("DESCRIBE", "交费用户积分划转成功");
			resultJson.put("POWERUSERNOLIST", powerUserNoReturn);
			return JSONObject.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnSucceed(resultJson)));
		} catch (Exception e) {
			log.error("交费用户积分划转异常",e);
		}
		return jsonObject;
	}
	/**
	 * 交费用户积分划转(new)
	 * 
	 * @param jsonObject() 注意： 1、用户缴费是多个户号需要处理
	 *        2、分布式是事务的处理，户号积分扣减成功，但是资产中心积分未增加，要怎么处理。
	 *  神坑    转化比例！！！！！！！！！！！！！！！！！
	 *  ！！！！！！！！！！！！！！！！！！！！！！！    
	 *        建议： 1、生成订单、标记状态、跟踪好订单信息 2、异步处理
	 */
	@Override
	public JSONObject payChangeIntegralByPower(JSONObject json) {
		JSONObject jsonObject = null;
		//户号接口地址
		String QUERY_URL = urlConfigUtil.getUrlByKey(RedisKey.URLCON_PREFIXX.getKey(), RedisKey.HOUSE_INTEGRAL_QUERY.getKey());
		String TRANSFER_URL = urlConfigUtil.getUrlByKey(RedisKey.URLCON_PREFIXX.getKey(), RedisKey.HOUSE_INTEGRAL_TRANSFER.getKey());
		try {
			List<Map<String, Object>> powerUserNoReturn = new ArrayList<Map<String, Object>>();
			// 1、解析参数
			String LOGIN_ID = json.getString("LOGIN_ID");// 登录账户ID
			String UN_ID = json.getString("UN_ID");// 统一用户ID
			String BUSINESS_ID = json.getString("ACCOUNT_MAIN_ID");// 业务ID
			String list = json.getString("LIST");// 循环域
			String poweruserlist = json.getString("POWERUSERNOLIST");// 绑定关系循环域
			JSONArray array = JSON.parseArray(list);// 缴费list
			JSONArray array1 = JSON.parseArray(poweruserlist);// 绑定关系list
			JSONObject returnJson = new JSONObject();
			//双重遍历，获取每一个交费户号的绑定关系类型03强绑定  04未手动绑定/无绑定关系 00手动绑定 05高压用户不划转
			for(int i = 0; i < array1.size(); i++) {
				log.info("【户号中心查询】URL：" + QUERY_URL);
				String ORG_NO =array1.getJSONObject(i).getString("ORG_NO");// 供电单位编号
				String PROVINCE_CODE = array1.getJSONObject(i).getString("PROVINCE_CODE");// 网省编号
				String POWER_USER_NO = array1.getJSONObject(i).getString("POWER_USER_NO");// 户号
				BigDecimal PAY_NUM = new BigDecimal(array1.getJSONObject(i).getString("PAY_NUM"));// 交费金额
				JSONObject object = new JSONObject();
				object.put("POWER_USER_NO", POWER_USER_NO);
				object.put("PROVINCE_CODE", PROVINCE_CODE);
				object.put("ORG_NO",ORG_NO);
				log.info("【户号中心查询】请求参数：" + object);
				String result = RequestUtils.sendPost(QUERY_URL, object.toString());
				log.info("【户号中心查询】返回参数：" + result);
				JSONObject balanceJson = JSONObject.parseObject(result);
				if (!"0".equals(balanceJson.getString("code"))) {
					returnJson.put("INTEGRAL_NUM", "0");
					returnJson.put("STATUS", "02");
					returnJson.put("MESSAGE","户号中心查询失败");
					powerUserNoReturn.add(returnJson);
					continue;
				}
				//用户的积分余额
				String content = balanceJson.getString("content");
				JSONObject jo = JSON.parseObject(content);
				BigDecimal Balance = jo.getBigDecimal("BALANCE");
				if("0".equals(Balance.compareTo(BigDecimal.ZERO))){
					returnJson.put("INTEGRAL_NUM", "0");
					returnJson.put("STATUS", "05");
					returnJson.put("MESSAGE","户号积分为0");
					powerUserNoReturn.add(returnJson);
					continue;
				}
				// 转化积分上限
				BigDecimal conversionIntegral = PAY_NUM.multiply(proportion);
				// 调用用户积分余额扣减,调用资产中心接口给账户增加积分
				BigDecimal deductionIntegral = new BigDecimal("0");
				// 如果扣减积分小于扣减上限,扣减扣减积分
				if (Balance.compareTo(conversionIntegral) <= 0) {
					deductionIntegral = Balance;
				} else {
					// 如果扣减积分大于扣减上限,扣减上限积分
					deductionIntegral = conversionIntegral;
				}
				log.info("转化积分比例："+proportion+"，转化积分上限："+conversionIntegral+"，转化积分："+deductionIntegral);
				returnJson.put("INTEGRAL_NUM", deductionIntegral.toString());
				//				//调用用户积分余额扣减接口
				//				String jsonDedConsBalanceResult=dedConsBalance(TRANSFER_URL, PROVINCE_CODE, ORG_NO, POWER_USER_NO,BUSINESS_ID, "01", "01", deductionIntegral.toString());
				//				JSONObject jsonDedCons=JSONObject.parseObject(jsonDedConsBalanceResult);
				//				if(!"0".equals(jsonDedCons.get("code").toString())) {
				//					returnJson.put("STATUS", "02");
				//					returnJson.put("MESSAGE","户号中心扣减失败");
				//					powerUserNoReturn.add(returnJson);
				//					continue;
				//				}
				//调用资产中心账号增加接口
				JSONObject addjson = new JSONObject();
				addjson.put("BUSINESS_ID",BUSINESS_ID);
				addjson.put("SOURCE_DESCRIBE", "交费用户积分划转");
				addjson.put("INCOME_NUM", deductionIntegral.toString());
				addjson.put("INCOME_SOURCE", "01");
				addjson.put("OPERATION_STATUS", "01");
				addjson.put("LOGIN_ACCOUNT_ID", UN_ID);
				addjson.put("USER_NAME", AtbashUtils.encrypt(json.getString("USER_NAME")));
				addjson.put("IP", json.getString("IP"));
				//addjson.put("CHANNEL_RESOURCE", json.getString("CHANNEL_RESOURCE"));
				//addjson.put("IP", json.getString("IP"));
				addjson.put("CHANNEL_NO", json.getString("CHANNEL_NO"));
				JSONObject accountServiceReturn = modifyIntegral(addjson, AccountConstant.AMT_DIRECTION_IN);
				if (!"01".equals(accountServiceReturn.get("resultCode").toString())) {
					//户号扣减的添加回去未处理
					returnJson.put("STATUS", "02");
					returnJson.put("MESSAGE","资产中心添加失败");
					powerUserNoReturn.add(returnJson);
					continue;
				}
				//调用用户积分余额扣减接口
				String jsonDedConsBalanceResult=dedConsBalance(TRANSFER_URL, PROVINCE_CODE, ORG_NO, POWER_USER_NO,BUSINESS_ID, "01", "01", deductionIntegral.toString());
				JSONObject jsonDedCons=JSONObject.parseObject(jsonDedConsBalanceResult);
				if(!"0".equals(jsonDedCons.get("code").toString())) {
					returnJson.put("STATUS", "02");
					returnJson.put("MESSAGE","户号中心扣减失败");
					powerUserNoReturn.add(returnJson);
					continue;
				}
				returnJson.put("STATUS", "01");
				returnJson.put("MESSAGE","交费积分划转成功");
				powerUserNoReturn.add(returnJson);
			}
			JSONObject resultJson = new JSONObject();
			resultJson.put("ACCOUNT_MAIN_ID", BUSINESS_ID);
			resultJson.put("LOGIN_ID", LOGIN_ID);
			resultJson.put("UN_ID", UN_ID);
			//			resultJson.put("DESCRIBE", "交费用户积分划转成功");
			resultJson.put("POWERUSERNOLIST", powerUserNoReturn);
			return JSONObject.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnSucceed(resultJson)));
		} catch (Exception e) {
			log.error("交费用户积分划转异常",e);
		}
		return jsonObject;









		//			
		//			List<Map<String, String>> rlist=new ArrayList<Map<String, String>>();
		//			for (int i = 0; i < array.size(); i++) {
		//				Map<String, String> map=new HashMap<String, String>();
		//				String consNo=array.getJSONObject(i).getString("POWER_USER_NO");
		//				map.put("POWER_USER_NO", consNo);
		//				String status="04";//默认为无绑定关系
		//				//根据户号查询是否有强绑定关系
		//				List<EcBpTransferBinding> selectQBindingByConsNo = ecBpTransferBindingMapper.selectQBindingByConsNo(consNo);
		//				if(selectQBindingByConsNo!=null&&selectQBindingByConsNo.size()>0){
		//					status="03";
		//				}else{
		//					for (int j = 0; j < array1.size(); j++) {
		//						if(consNo.equals(array1.getJSONObject(j).getString("consNo_dst"))){
		//							if(AccountConstant.BINDING_HIGHB.equals(array1.getJSONObject(j).getString("elecTypeCode"))) {
		//								status="05";
		//							}else {
		//									status="00";
		//									map.put("ORG_NO", array.getJSONObject(i).getString("ORG_NO"));
		//									map.put("PROVINCE_CODE", array.getJSONObject(i).getString("PROVINCE_CODE"));
		//									map.put("PAY_NUM", array.getJSONObject(i).getString("PAY_NUM"));
		//							}
		////							if(AccountConstant.BINDING_SDBD.equals(array1.getJSONObject(j).getString("constType"))){
		////								status="00";
		////								map.put("ORG_NO", array.getJSONObject(i).getString("ORG_NO"));
		////								map.put("PROVINCE_CODE", array.getJSONObject(i).getString("PROVINCE_CODE"));
		////								map.put("PAY_NUM", array.getJSONObject(i).getString("PAY_NUM"));
		////							}else{
		////								status="03";
		////							}
		//						}
		//					}
		//				}
		//				map.put("STATUS", status);
		//				log.info(consNo+":"+status);
		//				rlist.add(map);
		//			}
		//			for (Map<String, String> map2 : rlist) {
		//				JSONObject returnJson = new JSONObject();
		//				String POWER_USER_NO=map2.get("POWER_USER_NO");//户号
		//				String status=map2.get("STATUS");//状态 03强绑定  04未手动绑定/无绑定关系 00手动绑定  05高压用户不划转
		//				returnJson.put("POWER_USER_NO", POWER_USER_NO);
		//				returnJson.put("CREATE_TIIME", new Date());
		//				if(status.equals("03")||status.equals("04")){
		//					returnJson.put("INTEGRAL_NUM", "0");
		//					returnJson.put("STATUS", status);
		//					returnJson.put("MESSAGE",status.equals("03")?"已有强绑定":"未手动绑定");
		//				}
		//				else if(status.equals("05")) {
		//					returnJson.put("INTEGRAL_NUM", "0");
		//					returnJson.put("STATUS", status);
		//					returnJson.put("MESSAGE","高压用户不划转");
		//				}
		//				else{
		//					log.info("【户号中心查询】URL：" + QUERY_URL);
		//					String ORG_NO =map2.get("ORG_NO");// 供电单位编号
		//					String PROVINCE_CODE = map2.get("PROVINCE_CODE");// 网省编号
		//					BigDecimal PAY_NUM = new BigDecimal(map2.get("PAY_NUM"));// 交费金额
		//					JSONObject object = new JSONObject();
		//					object.put("POWER_USER_NO", POWER_USER_NO);
		//					object.put("PROVINCE_CODE", PROVINCE_CODE);
		//					object.put("ORG_NO",ORG_NO);
		//					log.info("【户号中心查询】请求参数：" + object);
		//					String result = RequestUtils.sendPost(QUERY_URL, object.toString());
		//					log.info("【户号中心查询】返回参数：" + result);
		//					JSONObject balanceJson = JSONObject.parseObject(result);
		//					if (!"0".equals(balanceJson.getString("code"))) {
		//						returnJson.put("INTEGRAL_NUM", "0");
		//						returnJson.put("STATUS", "02");
		//						returnJson.put("MESSAGE","户号中心查询失败");
		//						powerUserNoReturn.add(returnJson);
		//						continue;
		//					}
		//					//用户的积分余额
		//					String content = balanceJson.getString("content");
		//					JSONObject jo = JSON.parseObject(content);
		//					BigDecimal Balance = jo.getBigDecimal("BALANCE");
		//					if("0".equals(Balance.compareTo(BigDecimal.ZERO))){
		//						returnJson.put("INTEGRAL_NUM", "0");
		//						returnJson.put("STATUS", "05");
		//						returnJson.put("MESSAGE","户号积分为0");
		//						powerUserNoReturn.add(returnJson);
		//						continue;
		//					}
		//					// 转化积分上限
		//					BigDecimal conversionIntegral = PAY_NUM.multiply(proportion);
		//					// 调用用户积分余额扣减,调用资产中心接口给账户增加积分
		//					BigDecimal deductionIntegral = new BigDecimal("0");
		//					// 如果扣减积分小于扣减上限,扣减扣减积分
		//					if (Balance.compareTo(conversionIntegral) <= 0) {
		//						deductionIntegral = Balance;
		//					} else {
		//						// 如果扣减积分大于扣减上限,扣减上限积分
		//						deductionIntegral = conversionIntegral;
		//					}
		//					log.info("转化积分比例："+proportion+"，转化积分上限："+conversionIntegral+"，转化积分："+deductionIntegral);
		//					returnJson.put("INTEGRAL_NUM", deductionIntegral.toString());
		//					//调用用户积分余额扣减接口
		//					String jsonDedConsBalanceResult=dedConsBalance(TRANSFER_URL, PROVINCE_CODE, ORG_NO, POWER_USER_NO,BUSINESS_ID, "01", "01", deductionIntegral.toString());
		//					JSONObject jsonDedCons=JSONObject.parseObject(jsonDedConsBalanceResult);
		//					if(!"0".equals(jsonDedCons.get("code").toString())) {
		//						returnJson.put("STATUS", "02");
		//						returnJson.put("MESSAGE","户号中心扣减失败");
		//						powerUserNoReturn.add(returnJson);
		//						continue;
		//					}
		//					//调用资产中心账号增加接口
		//					JSONObject addjson = new JSONObject();
		//					addjson.put("BUSINESS_ID",BUSINESS_ID);
		//					addjson.put("SOURCE_DESCRIBE", "交费用户积分划转");
		//					addjson.put("INCOME_NUM", deductionIntegral.toString());
		//					addjson.put("INCOME_SOURCE", "01");
		//					addjson.put("OPERATION_STATUS", "01");
		//					addjson.put("LOGIN_ACCOUNT_ID", UN_ID);
		//					JSONObject accountServiceReturn = modifyIntegral(addjson, AccountConstant.AMT_DIRECTION_IN);
		//					if (!"01".equals(accountServiceReturn.get("resultCode").toString())) {
		//						returnJson.put("STATUS", "02");
		//						returnJson.put("MESSAGE","资产中心添加失败");
		//						powerUserNoReturn.add(returnJson);
		//						continue;
		//					}
		//					returnJson.put("STATUS", "01");
		//					returnJson.put("MESSAGE","交费积分划转成功");
		//				}
		//				powerUserNoReturn.add(returnJson);
		//			}
		//			JSONObject resultJson = new JSONObject();
		//			resultJson.put("ACCOUNT_MAIN_ID", BUSINESS_ID);
		//			resultJson.put("LOGIN_ID", LOGIN_ID);
		//			resultJson.put("UN_ID", UN_ID);
		//			//			resultJson.put("DESCRIBE", "交费用户积分划转成功");
		//			resultJson.put("POWERUSERNOLIST", powerUserNoReturn);
		//			return JSONObject.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnSucceed(resultJson)));
		//		} catch (Exception e) {
		//			log.error("交费用户积分划转异常",e);
		//		}
		//		return jsonObject;
	}
	/**
	 * 交费用户积分划转(dxp)
	 * 
	 * @param jsonObject() 注意： 1、用户缴费是多个户号需要处理
	 *        2、分布式是事务的处理，户号积分扣减成功，但是资产中心积分未增加，要怎么处理。
	 *  神坑    转化比例！！！！！！！！！！！！！！！！！
	 *  ！！！！！！！！！！！！！！！！！！！！！！！    
	 *        建议： 1、生成订单、标记状态、跟踪好订单信息 2、异步处理
	 */
	@Override
	@Transactional(rollbackFor=Exception.class)
	public JSONObject payChangeIntegralByDxp(JSONObject json) {
		JSONObject jsonObject = null;
		//户号接口地址
		String QUERY_URL_TRANSFER = urlConfigUtil.getUrlByKey(RedisKey.URLCON_PREFIXX.getKey(), RedisKey.INTER_INTEGRAL_TRANSFER.getKey());
		String QUERY_URL_INTER = urlConfigUtil.getUrlByKey(RedisKey.URLCON_PREFIXX.getKey(), RedisKey.INTER_INTEGRAL_QUERY.getKey());
		String uuid=UUIDUtil.getUUID();
		try {
			List<Map<String, Object>> powerUserNoReturn = new ArrayList<Map<String, Object>>();
			// 1、解析参数
			String LOGIN_ID = json.getString("LOGIN_ID");// 登录账户ID
			String UN_ID = json.getString("UN_ID");// 统一用户ID
			String ACCOUNT_MAIN_ID = json.getString("ACCOUNT_MAIN_ID");// 业务ID
			String list = json.getString("LIST");// 循环域
			String poweruserlist = json.getString("POWERUSERNOLIST");// 绑定关系循环域
			BigDecimal deductionNum=json.getBigDecimal("INTEGRAL_DEDUCTION");//抵扣积分
			JSONArray array = JSON.parseArray(list);// 缴费list
			JSONArray array1 = JSON.parseArray(poweruserlist);// 绑定关系list
			JSONObject returnJson = new JSONObject();
			JSONObject resultJson = new JSONObject();
			//划转总积分
			BigDecimal totalBalance=new BigDecimal(0);
			List<EcBpInComeIntegral> incomeIntegralList=new ArrayList<EcBpInComeIntegral>();//积分收入表List
			List<EcBpConsNoIntegral> consNoIntegralList=new ArrayList<EcBpConsNoIntegral>();//户号账户表List
			String accountId=UN_ID;
			String channelNo=json.getString("CHANNEL_NO");
			String serialNo=json.getString("ACCOUNT_MAIN_ID");
			String accountName=json.getString("LOGIN_ID");
			JSONObject queryJson=new JSONObject();
			queryJson.put("CHANNEL_NO",json.getString("CHANNEL_NO"));
			queryJson.put("ACCOUNT_ID",json.getString("UN_ID"));
			if(json.containsKey("ACCOUNT_NAME")){
				queryJson.put("ACCOUNT_NAME",json.getString("ACCOUNT_NAME"));
			}else {
				queryJson.put("ACCOUNT_NAME",json.getString("UN_ID"));
			}
			//查询账户积分总表,若无,需调用 积分账户新增接口
			newAccountServiceImpl.queryIntegral(queryJson);
			if(deductionNum!=null&&deductionNum!=BigDecimal.ZERO){
				//调用扣减接口,扣减抵扣金额
				JSONObject reqJson=new JSONObject();
				reqJson.put("ACCOUNT_NAME", accountName);//账户名称
				reqJson.put("ACCOUNT_ID", accountId);//登录账户ID
				reqJson.put("BUSINESS_ID", serialNo);//业务ID=流水号=支出ID=收支流水号
				reqJson.put("INTEGRAL", deductionNum);//抵扣积分
				reqJson.put("DEAL_TIME", TimeUtil.getDate("YYYYMMddHHmmssSSS"));//交易时间 YYYYMMddHHmmssSSS
				reqJson.put("BUSS_DISCRIBLE", NewAccountConstant.BUSS_TYPE_MAP.get(NewAccountConstant.BUSS_TYPE_JFJFDK));//业务描述、备注
				reqJson.put("CHANNEL_NO",channelNo);//业务描述、备注
				reqJson.put("BUSS_TYPE", NewAccountConstant.BUSS_TYPE_JFJFDK);//业务类型-缴费抵扣积分
				reqJson.put("LOG_MSG","【抵扣积分扣减】");
				JSONObject retJson = newAccountServiceImpl.deductionIntegral(reqJson,false);//false,不同步至资产中心
				JSONObject resultJson1=new JSONObject();
				if("-1".equals(retJson.getString("rcode"))){//扣减失败
					resultJson1.put("STATUS", NewAccountConstant.RETURN_CODE_FAIL);
					resultJson1.put("DESCRIBE", "抵扣积分扣减失败");
					log.error("抵扣积分{}扣减失败",deductionNum);
					return ResultModel.ReturnErrorJson(resultJson1);
				}
				JSONObject content = retJson.getJSONObject("content");
				resultJson.put("DEDUCTION_ID", content.getString("BUSINESS_ID"));
				log.info("抵扣积分{}扣减成功",deductionNum);
			}
			//newAccountServiceImpl.queryIntegral(queryJson);
			//双重遍历，获取每一个交费户号的绑定关系类型03强绑定  04未手动绑定/无绑定关系 00手动绑定 05高压用户不划转
//			JSONArray addjsonlist=new JSONArray();
			for(int i = 0; i < array1.size(); i++) {
				log.info("【户号中心查询(dxp)】URL：" + QUERY_URL_INTER);
				String ORG_NO =array1.getJSONObject(i).getString("ORG_NO");// 供电单位编号
				String PROVINCE_CODE = array1.getJSONObject(i).getString("PROVINCE_CODE");// 网省编号
				String POWER_USER_NO = array1.getJSONObject(i).getString("POWER_USER_NO");// 户号
				String BUSINESS_ID = array1.getJSONObject(i).getString("BUSINESS_ID");// 业务id
				BigDecimal PAY_NUM = new BigDecimal(array1.getJSONObject(i).getString("PAY_NUM"));// 交费金额
				JSONObject object = new JSONObject();
				String result=queryConsBalanceByInner(QUERY_URL_INTER, POWER_USER_NO, PROVINCE_CODE, ORG_NO,UN_ID,LOGIN_ID,"0");
				JSONObject balanceJson = JSONObject.parseObject(result);
				if (!"0".equals(balanceJson.getString("rcode"))) {
					returnJson.put("INTEGRAL_NUM", "0");
					returnJson.put("STATUS", "02");
					returnJson.put("CHECKINGID", uuid);
					returnJson.put("MESSAGE",balanceJson.getString("message"));
					returnJson.put("BUSINESS_ID",BUSINESS_ID);
					powerUserNoReturn.add(returnJson);
					continue;
				}
				//用户的积分余额
				String content = balanceJson.getString("content");
				JSONObject jo = JSON.parseObject(content);
				BigDecimal Balance = jo.getBigDecimal("BALANCE");
				if("0".equals(Balance.compareTo(BigDecimal.ZERO))){
					returnJson.put("INTEGRAL_NUM", "0");
					returnJson.put("STATUS", "05");
					returnJson.put("CHECKINGID", uuid);
					returnJson.put("MESSAGE","户号积分为0");
					returnJson.put("BUSINESS_ID",BUSINESS_ID);
					powerUserNoReturn.add(returnJson);
					continue;
				}
				// 转化积分上限
				BigDecimal conversionIntegral = PAY_NUM.multiply(proportion);
				// 调用用户积分余额扣减,调用资产中心接口给账户增加积分
				BigDecimal deductionIntegral = new BigDecimal("0");
				// 如果扣减积分小于扣减上限,扣减扣减积分
				if (Balance.compareTo(conversionIntegral) <= 0) {
					deductionIntegral = Balance;
				} else {
					// 如果扣减积分大于扣减上限,扣减上限积分
					deductionIntegral = conversionIntegral;
				}
				log.info("转化积分比例："+proportion+"，转化积分上限："+conversionIntegral+"，转化积分："+deductionIntegral);
				returnJson.put("INTEGRAL_NUM", deductionIntegral.toString());
				
				//调用用户积分余额扣减接口
				String jsonDedConsBalanceResult=dedConsBalanceByInner(QUERY_URL_TRANSFER, PROVINCE_CODE, ORG_NO, POWER_USER_NO, BUSINESS_ID, "01", "01", deductionIntegral.toString(),UN_ID, LOGIN_ID,"0",uuid);
				JSONObject jsonDedCons=JSONObject.parseObject(jsonDedConsBalanceResult);
				if(!"0".equals(jsonDedCons.get("rcode").toString())) {
					returnJson.put("INTEGRAL_NUM", "0");
					returnJson.put("STATUS", "02");
					returnJson.put("CHECKINGID", uuid);
					returnJson.put("MESSAGE",jsonDedCons.getString("message"));
					returnJson.put("BUSINESS_ID",BUSINESS_ID);
					powerUserNoReturn.add(returnJson);
					continue;
				}
				returnJson.put("INTEGRAL_NUM", deductionIntegral.toString());
				returnJson.put("STATUS", "01");
				returnJson.put("CHECKINGID", uuid);
				returnJson.put("MESSAGE","交费积分划转成功");
				returnJson.put("BUSINESS_ID",BUSINESS_ID);
				powerUserNoReturn.add(returnJson);
				//调用资产中心账号增加接口
//				JSONObject addjson = new JSONObject();
//				
//				addjson.put("BUSINESS_ID",BUSINESS_ID);
//				addjson.put("SOURCE_DESCRIBE", "交费用户积分划转");
//				addjson.put("INCOME_NUM", deductionIntegral.toString());
//				addjson.put("INCOME_SOURCE", "01");
//				addjson.put("OPERATION_STATUS", "01");
//				addjson.put("LOGIN_ACCOUNT_ID", UN_ID);
//				addjson.put("USER_NAME", AtbashUtils.encrypt(json.getString("USER_NAME")));
//				addjson.put("IP", json.getString("IP"));
//				addjson.put("CHANNEL_NO", json.getString("CHANNEL_NO"));
//				JSONObject accountServiceReturn = modifyIntegral(addjson, AccountConstant.AMT_DIRECTION_IN);
//				if (!"01".equals(accountServiceReturn.get("resultCode").toString())) {
//					//户号扣减的添加回去未处理
//					returnJson.put("INTEGRAL_NUM", "0");
//					returnJson.put("STATUS", "02");
//					returnJson.put("MESSAGE","资产中心添加失败");
//					returnJson.put("BUSINESS_ID",BUSINESS_ID);
//					powerUserNoReturn.add(returnJson);
//					continue;
//				}
//				returnJson.put("INTEGRAL_NUM", deductionIntegral.toString());
//				returnJson.put("STATUS", "01");
//				returnJson.put("MESSAGE","交费积分划转成功");
//				returnJson.put("BUSINESS_ID",BUSINESS_ID);
//				powerUserNoReturn.add(returnJson);
//				totalBalance=totalBalance.add(deductionIntegral);
				/////////////////////////////////////新账户体系积分数据添加处理开始////////////////////////////////////////
				/////////////////////////////////////新账户体系积分数据添加处理开始////////////////////////////////////////
				/////////////////////////////////////新账户体系积分数据添加处理开始////////////////////////////////////////
				BigDecimal balance=deductionIntegral;//转换积分量
				//遍历该户号下的积分明细
				//积分收入表
				EcBpInComeIntegral incomeIntegral=new EcBpInComeIntegral();
				incomeIntegral.setIncomeId(uuid);//收入ID
				incomeIntegral.setAccountId(accountId);//总账户ID
				incomeIntegral.setConsNo(POWER_USER_NO);//户号
				incomeIntegral.setProvinceCode(PROVINCE_CODE);//省码
				incomeIntegral.setOrgNo(ORG_NO);//供电单位
				//incomeIntegral.setPowerId(uuid);//电力积分id
				incomeIntegral.setIncomeChannel(channelNo);//收入来源渠道编码
				incomeIntegral.setSerialNo(serialNo);//收入来源流水号,使用统一流水号
				incomeIntegral.setIncomeSource(NewAccountConstant.BUSS_TYPE_DLJFZR);//业务类型,04：积分划转
				incomeIntegral.setIncomeType(NewAccountConstant.OPERATION_TYPE_ZD);//收入类型,01自动
				incomeIntegral.setSourceInstructions("合作平台积分缴费新增(用电编号："+POWER_USER_NO+")");//来源说明/积分类型
				incomeIntegral.setSourceNumber(balance);//来源数量
				incomeIntegral.setIncomeBalance(balance);//收入总金额
				incomeIntegral.setUsableBalance(balance);//可用金额
				incomeIntegral.setChannelCreateTime(TimeUtil.getDate("YYYYMMddHHmmssSSS"));//渠道积分生成日期YYYYMMdd/交易时间
				incomeIntegral.setIncomeTime(TimeUtil.getDate("YYYYMMdd"));//收入日期YYYYMMdd
				incomeIntegral.setStaleTime((Integer.parseInt(TimeUtil.getDate("YYYY"))+3)+"1231");//过期日期YYYYMMdd
				incomeIntegral.setStatus(NewAccountConstant.INCOME_INTEGRAL_STATUS_USABLE);//状态01:可用
				incomeIntegral.setCreateTime(TimeUtil.getDate("YYYYMMddHHmmssSSS"));//创建时间
				incomeIntegralList.add(incomeIntegral);

				EcBpConsNoIntegral consNoIntegral=new EcBpConsNoIntegral();//户号账户实体
				consNoIntegral.setConsNo(POWER_USER_NO);//户号
				consNoIntegral.setAccountId(accountId);//总账户ID
				consNoIntegral.setProvinceCode(PROVINCE_CODE);//省码
				consNoIntegral.setCityCode(ORG_NO);//地市编码------------？？？？？？？？？？？
				consNoIntegral.setHsdwNo(ORG_NO);//核算单位编码-------------？？？？？？？？？？？
				consNoIntegral.setCreateTime(TimeUtil.getDate("YYYYMMddHHmmssSSS"));//创建时间
				consNoIntegral.setUpdateTime(TimeUtil.getDate("YYYYMMddHHmmssSSS"));//修改时间
				consNoIntegral.setBalance(balance);//积分余额
				for (int j = 0; j < consNoIntegralList.size(); j++) {
					EcBpConsNoIntegral ecBpConsNoIntegral = consNoIntegralList.get(j);
					if(POWER_USER_NO.equals(ecBpConsNoIntegral.getConsNo())){
						consNoIntegral.setBalance(consNoIntegral.getBalance().add(ecBpConsNoIntegral.getBalance()));
						consNoIntegralList.remove(j);//移除该条户号记录
					}
				}
				consNoIntegralList.add(consNoIntegral);
				/////////////////////////////////////新账户体系积分数据添加处理结束////////////////////////////////////////
			}
			/////////////////////////////////////新账户体系积分数据添加处理开始////////////////////////////////////////
			EcBpAccountIntegralDetail accountIntegralDetail = new EcBpAccountIntegralDetail();
			String detailId=UUIDUtil.getUUID();//明细ID（UUID）返回报文中的业务ID
			if(incomeIntegralList.size()>0) {
				//插入积分收入表
				int incomeNum=incomeIntegralMapper.insertList(incomeIntegralList);
				log.info("积分收入表插入成功,条数:"+incomeNum);
				//插入户号账户表
				int consNoNum=consNoIntegralMapper.batchInsertOrUpdate(consNoIntegralList);
				log.info("积分户号账户表插入或更新成功,条数:"+consNoNum);
				//插入 积分明细表
				accountIntegralDetail.setDetailId(detailId);//明细ID（UUID）
				accountIntegralDetail.setAccountId(accountId);//总账户ID
				accountIntegralDetail.setAccountName(accountName);//账户名称
				accountIntegralDetail.setSerialNo(serialNo);//收支流水号
				accountIntegralDetail.setDealType(NewAccountConstant.DEAL_TYPE_INCOME);//业务方向
				accountIntegralDetail.setBalance(totalBalance);//积分金额
				accountIntegralDetail.setCreateTime(TimeUtil.getDate("YYYYMMddHHmmssSSS"));//创建时间
				accountIntegralDetail.setDealTime(TimeUtil.getDate("YYYYMMddHHmmssSSS"));//交易时间=创建时间
				accountIntegralDetail.setBussDiscrible("01".equals("02")?"积分划转":"缴费积分划转");//业务描述
				accountIntegralDetail.setBussType(NewAccountConstant.BUSS_TYPE_DLJFZR);//业务类型 04:积分划转
				accountIntegralDetail.setAcctDate(TimeUtil.getDate("YYYYMMddHHmmssSSS"));//账务日期
				accountIntegralDetail.setChannelNo(channelNo);//渠道编码
				accountIntegralDetailMapper.insert(accountIntegralDetail);
				//更新 积分账户总表
				//查询账户积分总表,若无,需调用 积分账户新增接口
				EcBpAccountIntegral accountIntegral = accountIntegralMapper.selectIntegralByUnionId(accountId);
				accountIntegral.setCreateTime(TimeUtil.getDate("YYYYMMddHHmmssSSS"));
				accountIntegral.setBalance(accountIntegral.getBalance().add(totalBalance));//总可用积分
				accountIntegralMapper.update(accountIntegral);
				log.info("积分账户总表更新成功,总可用积分:"+accountIntegral.getBalance());
				
				
				
				
				
				
			}
			/////////////////////////////////////新账户体系积分数据添加处理结束////////////////////////////////////////
			//调用资产中心账号增加接口
			JSONObject addjson = new JSONObject();
			addjson.put("BUSINESS_ID",ACCOUNT_MAIN_ID);
			addjson.put("SOURCE_DESCRIBE", "交费用户积分划转");
			addjson.put("INCOME_NUM", totalBalance.toString());
			addjson.put("INCOME_SOURCE", "01");
			addjson.put("OPERATION_STATUS", "01");
			addjson.put("LOGIN_ACCOUNT_ID", UN_ID);
			addjson.put("USER_NAME", AtbashUtils.encrypt(json.getString("USER_NAME")));
			addjson.put("IP", json.getString("IP"));
			addjson.put("CHANNEL_NO", json.getString("CHANNEL_NO"));
			JSONObject accountServiceReturn = modifyIntegral(addjson, AccountConstant.AMT_DIRECTION_IN);
			String resultCode=accountServiceReturn.getString("resultCode");
			if(resultCode.equals("01")){
				accountIntegralDetail.setStatus("1");//同步至资产中心状态（0:失败1:成功）
			}else{
				accountIntegralDetail.setStatus("0");//同步至资产中心状态（0:失败1:成功）
			}
			accountIntegralDetailMapper.update(accountIntegralDetail);
			log.info("积分账户明细表更新成功,流水号:"+serialNo+",同步状态:"+accountServiceReturn.getString("resultCode"));
			//如果资产中心失败，直接返回失败
			if(accountServiceReturn.getString("resultCode").equals(NewAccountConstant.RETURN_CODE_FAIL)){
				return ResultModel.ReturnErrorJson();
			}
			
			resultJson.put("ACCOUNT_MAIN_ID", ACCOUNT_MAIN_ID);
			resultJson.put("LOGIN_ID", LOGIN_ID);
			resultJson.put("UN_ID", UN_ID);
			resultJson.put("TOTALBALANCE", totalBalance.toString());
			//			resultJson.put("DESCRIBE", "交费用户积分划转成功");
			resultJson.put("POWERUSERNOLIST", powerUserNoReturn);
			return JSONObject.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnSucceed(resultJson)));
		} catch (Exception e) {
			log.error("交费用户积分划转异常",e);
		}
		return jsonObject;

	}
	/**
	 * 用户点击积分中心积分划转(20181023新接口dxp)
	 * @param jsonObject( PROVINCE_CODE	网省编号
	 *				ORG_NO	供电单位编码
	 *				BUSINESS_TYPE	业务类型
	 *				BUSINESS_ID	业务ID
	 *				LOGIN_ACCOUNT_ID	登录账户ID)
	 * 
	 *            注意： 1、分布式是事务的处理，户号积分扣减成功，但是资产中心积分未增加，要怎么处理。
	 *            2、接口的响应时间，因为此接口提供给用户点击需要提升用户体验。 建议： 1、生成订单、标记状态、跟踪好订单信息 2、异步处理
	 * 
	 * 
	 */
	@Override
	public JSONObject changeIntegralByDxp(JSONObject json) {
		// 初始化接口地址
		String QUERY_URL_TRANSFER = urlConfigUtil.getUrlByKey(RedisKey.URLCON_PREFIXX.getKey(), RedisKey.INTER_INTEGRAL_TRANSFER.getKey());
		String QUERY_URL_INTER = urlConfigUtil.getUrlByKey(RedisKey.URLCON_PREFIXX.getKey(), RedisKey.INTER_INTEGRAL_QUERY.getKey());
		//String QUERY_URL = "http://localhost:10109/house/queryConsBalance";
		JSONObject jsonReturn = null;
		String PROVINCE_CODE = "";// 网省编号
		String ORG_NO = "";// 供电单位编码
		String CONS_NO = "";// 户号
		String BUSINESS_ID = "";// 业务ID
		try {

			if(json.containsKey("BUSINESS_ID")) {
				BUSINESS_ID = json.getString("BUSINESS_ID");// 业务ID
			}
			// 2、查询数据库绑定关系中强绑定关系的户号
			//直接获取绑定的户号信息
			JSONArray powerList = (JSONArray) json.get("POWERUSERNOLIST");
			JSONObject queryJson=new JSONObject();
			//{"CHANNEL_NO":"5","ACCOUNT_ID":"44f90082e9f74d979ab9bc2bd18c11a6","ACCOUNT_NAME":"王五"}
			queryJson.put("CHANNEL_NO",json.getString("CHANNEL_NO"));
			queryJson.put("ACCOUNT_ID",json.getString("LOGIN_ACCOUNT_ID"));
			queryJson.put("ACCOUNT_NAME",json.getString("ACCOUNT_NAME"));
			newAccountServiceImpl.queryIntegral(queryJson);
			String accountId=json.getString("LOGIN_ACCOUNT_ID");
			String channelNo=json.getString("CHANNEL_NO");
			String serialNo=json.getString("BUSINESS_ID");
			String accountName=json.getString("ACCOUNT_NAME");
			List<Map<String, String>> powerUserNoReturn= new ArrayList<Map<String,String>>();
			//划转总积分
			BigDecimal totalBalance=new BigDecimal(0);
			List<EcBpInComeIntegral> incomeIntegralList=new ArrayList<EcBpInComeIntegral>();//积分收入表List
			List<EcBpConsNoIntegral> consNoIntegralList=new ArrayList<EcBpConsNoIntegral>();//户号账户表List
			if(powerList!=null&&powerList.size()>0) {
				for (int i=0;i<powerList.size();i++) {
					String uuid=UUIDUtil.getUUID();
					JSONObject power = powerList.getJSONObject(i);
					if(power.containsKey("provinceId")) {
						PROVINCE_CODE = power.getString("provinceId");// 网省编号
					}else {
						log.info("用户划转省码是空");
					}
					if(power.containsKey("orgNo")) {
						ORG_NO = power.getString("orgNo");//供电单位编码
					}else {
						log.info("用户划转供电编码是空");
					}

					if(power.containsKey("consNo")) {
						CONS_NO = power.getString("consNo");//户号
					}else {
						log.info("用户划转户号是空");
					}
					Map<String, String> powerUserNoModel = new HashMap<>();
					//3、根据户号查询户号上得积分
					String jsonQueryResult=queryConsBalanceByInner(QUERY_URL_INTER, CONS_NO, PROVINCE_CODE, ORG_NO,power.getString("userId"),json.getString("accountName"),"1");
					log.info("查询户号积分========================》{}",jsonQueryResult);
					//以后自建和统一积分都走这里
					//String jsonQueryResult=queryConsBalanceByInner(QUERY_URL, e.getPowerUserNo(), PROVINCE_CODE, ORG_NO,LOGIN_ACCOUNT_ID,LOGIN_ACCOUNT);
					JSONObject jsonQuery=JSONObject.parseObject(jsonQueryResult);
					if(!"0".equals(jsonQuery.get("rcode").toString())) {
//						powerUserNoModel.put("POWER_USER_NO", CONS_NO);
//						powerUserNoModel.put("TOTAL_BALANCE", "0");
//						powerUserNoModel.put("STATUS", "02");
//						powerUserNoModel.put("DESC", jsonQuery.getString("message"));
//						//						powerUserNoModel.put("TOTAL_BALANCE", "1");
//						"boundWay":"01","consNo":"1313706203","elecTypeCode":"01","orgNo":"33402100107","proNo":"33101","provinceId":"33101"
						powerUserNoModel.put("BOUNDWAY", power.getString("boundWay"));
						powerUserNoModel.put("CONSNO", power.getString("consNo"));
						powerUserNoModel.put("CHECKINGID", uuid);
						powerUserNoModel.put("ELECTYPECODE", power.getString("elecTypeCode"));
						powerUserNoModel.put("ORGNO", power.getString("orgNo"));
						powerUserNoModel.put("PRONO", power.getString("proNo"));
						powerUserNoModel.put("PROVINCEID", power.getString("provinceId"));
						powerUserNoModel.put("TOTAL_BALANCE", "0");
						powerUserNoModel.put("STATUS", "02");
						powerUserNoModel.put("DESC", jsonQuery.getString("message"));
						powerUserNoReturn.add(powerUserNoModel);
						
						continue;
						//return jsonQuery;
					}
					JSONObject jsoncontent=JSONObject.parseObject(jsonQuery.get("content").toString());
					//可用余额大于零调用资产中新增接口
					if ((jsoncontent.getInteger("BALANCE")>0)) {
//						jsoncontent.put("BALANCE","1");
						//4、根据户号查询的结果扣减户号上所有的积分余额（自建划转）
						String jsonDedConsBalanceResult=dedConsBalanceByInner(QUERY_URL_TRANSFER, PROVINCE_CODE, ORG_NO, CONS_NO,BUSINESS_ID, "01", "01", jsoncontent.get("BALANCE").toString(),power.getString("userId"),json.getString("ACCOUNT_NAME"),"1",uuid);
						JSONObject jsonDedCons=JSONObject.parseObject(jsonDedConsBalanceResult);
						if(!"0".equals(jsonDedCons.get("rcode").toString())) {
//							powerUserNoModel.put("POWER_USER_NO", CONS_NO);
//							powerUserNoModel.put("TOTAL_BALANCE", jsoncontent.get("BALANCE").toString());
//							powerUserNoModel.put("STATUS", "02");
							powerUserNoModel.put("BOUNDWAY", power.getString("boundWay"));
							powerUserNoModel.put("CONSNO", power.getString("consNo"));
							powerUserNoModel.put("CHECKINGID", uuid);
							powerUserNoModel.put("ELECTYPECODE", power.getString("elecTypeCode"));
							powerUserNoModel.put("ORGNO", power.getString("orgNo"));
							powerUserNoModel.put("PRONO", power.getString("proNo"));
							powerUserNoModel.put("PROVINCEID", power.getString("provinceId"));
							powerUserNoModel.put("TOTAL_BALANCE", "0");
							powerUserNoModel.put("STATUS", "02");
							powerUserNoModel.put("DESC", "划转失败");
							powerUserNoReturn.add(powerUserNoModel);
							continue;
							//return jsonDedCons;
						}

//						powerUserNoModel.put("POWER_USER_NO", CONS_NO);
//						powerUserNoModel.put("TOTAL_BALANCE", jsoncontent.get("BALANCE").toString());
//						powerUserNoModel.put("STATUS", "01");
						powerUserNoModel.put("BOUNDWAY", power.getString("boundWay"));
						powerUserNoModel.put("CONSNO", power.getString("consNo"));
						powerUserNoModel.put("ELECTYPECODE", power.getString("elecTypeCode"));
						powerUserNoModel.put("ORGNO", power.getString("orgNo"));
						powerUserNoModel.put("PRONO", power.getString("proNo"));
						powerUserNoModel.put("CHECKINGID", uuid);
						powerUserNoModel.put("PROVINCEID", power.getString("provinceId"));
						powerUserNoModel.put("TOTAL_BALANCE", jsoncontent.get("BALANCE").toString());
						powerUserNoModel.put("STATUS", "01");
						powerUserNoModel.put("DESC", "划转成功");
						powerUserNoReturn.add(powerUserNoModel);
//						// 5、扣减之后调用资产中心新增积分的接口
//						JSONObject addjson = new JSONObject();
//						addjson.put("BUSINESS_ID", json.get("BUSINESS_ID").toString());
//						addjson.put("SOURCE_DESCRIBE", "积分划转");
//						addjson.put("INCOME_NUM", jsoncontent.get("BALANCE").toString());
//						addjson.put("INCOME_SOURCE", "01");
//						addjson.put("OPERATION_STATUS", "01");
//						addjson.put("LOGIN_ACCOUNT_ID", json.get("LOGIN_ACCOUNT_ID"));
//						JSONObject accountServiceReturn = modifyIntegral(addjson, AccountConstant.AMT_DIRECTION_IN);
//						log.info("账户中心添加接口返回参数：{}", accountServiceReturn);
//						if (!"01".equals(accountServiceReturn.get("resultCode").toString())) {
//							continue;
//						}
						totalBalance=totalBalance.add(jsoncontent.getBigDecimal("BALANCE"));
						/////////////////////////////////////新账户体系积分数据添加处理开始////////////////////////////////////////
						/////////////////////////////////////新账户体系积分数据添加处理开始////////////////////////////////////////
						/////////////////////////////////////新账户体系积分数据添加处理开始////////////////////////////////////////
						BigDecimal balance=jsoncontent.getBigDecimal("BALANCE");//转换积分量
						//遍历该户号下的积分明细
						//积分收入表
						EcBpInComeIntegral incomeIntegral=new EcBpInComeIntegral();
						incomeIntegral.setIncomeId(uuid);//收入ID
						incomeIntegral.setAccountId(accountId);//总账户ID
						incomeIntegral.setConsNo(CONS_NO);//户号
						incomeIntegral.setIncomeChannel(channelNo);//收入来源渠道编码
						incomeIntegral.setSerialNo(serialNo);//收入来源流水号,使用统一流水号
						incomeIntegral.setOrgNo(power.getString("orgNo"));//供电单位
						incomeIntegral.setPowerId(jsonDedCons.getString("id"));//电力积分id
						incomeIntegral.setProvinceCode(power.getString("provinceId"));//网省
						incomeIntegral.setIncomeSource(NewAccountConstant.BUSS_TYPE_DLJFZR);//业务类型,04：积分划转
						incomeIntegral.setIncomeType(NewAccountConstant.OPERATION_TYPE_ZD);//收入类型,01自动
						incomeIntegral.setSourceInstructions("合作平台积分转换新增(用电编号："+CONS_NO+")");//来源说明/积分类型
						incomeIntegral.setSourceNumber(balance);//来源数量
						incomeIntegral.setIncomeBalance(balance);//收入总金额
						incomeIntegral.setUsableBalance(balance);//可用金额
						incomeIntegral.setChannelCreateTime(TimeUtil.getDate("YYYYMMdd"));//渠道积分生成日期YYYYMMdd/交易时间
						incomeIntegral.setIncomeTime(TimeUtil.getDate("YYYYMMdd"));//收入日期YYYYMMdd
						incomeIntegral.setStaleTime((Integer.parseInt(TimeUtil.getDate("YYYY"))+3)+"1231");//过期日期YYYYMMdd
						incomeIntegral.setStatus(NewAccountConstant.INCOME_INTEGRAL_STATUS_USABLE);//状态01:可用
						incomeIntegral.setCreateTime(TimeUtil.getDate("YYYYMMddHHmmssSSS"));//创建时间
						incomeIntegralList.add(incomeIntegral);

						EcBpConsNoIntegral consNoIntegral=new EcBpConsNoIntegral();//户号账户实体
						consNoIntegral.setConsNo(CONS_NO);//户号
						consNoIntegral.setAccountId(accountId);//总账户ID
						consNoIntegral.setProvinceCode(PROVINCE_CODE);//省码
						consNoIntegral.setCityCode(ORG_NO);//地市编码------------？？？？？？？？？？？
						consNoIntegral.setHsdwNo(ORG_NO);//核算单位编码-------------？？？？？？？？？？？
						consNoIntegral.setCreateTime(TimeUtil.getDate("YYYYMMddHHmmssSSS"));//创建时间
						consNoIntegral.setUpdateTime(TimeUtil.getDate("YYYYMMddHHmmssSSS"));//修改时间
						consNoIntegral.setBalance(balance);//积分余额
						for (int j = 0; j < consNoIntegralList.size(); j++) {
							EcBpConsNoIntegral ecBpConsNoIntegral = consNoIntegralList.get(j);
							if(CONS_NO.equals(ecBpConsNoIntegral.getConsNo())){
								consNoIntegral.setBalance(consNoIntegral.getBalance().add(ecBpConsNoIntegral.getBalance()));
								consNoIntegralList.remove(i);//移除该条户号记录
							}
						}
						consNoIntegralList.add(consNoIntegral);
						/////////////////////////////////////新账户体系积分数据添加处理结束////////////////////////////////////////

					}else {
//						powerUserNoModel.put("POWER_USER_NO", CONS_NO);
//						powerUserNoModel.put("TOTAL_BALANCE", jsoncontent.get("BALANCE").toString());
//						powerUserNoModel.put("DESC", "户号积分不足");
//						powerUserNoModel.put("STATUS", "02");
						powerUserNoModel.put("BOUNDWAY", power.getString("boundWay"));
						powerUserNoModel.put("CONSNO", power.getString("consNo"));
						powerUserNoModel.put("ELECTYPECODE", power.getString("elecTypeCode"));
						powerUserNoModel.put("ORGNO", power.getString("orgNo"));
						powerUserNoModel.put("CHECKINGID", uuid);
						powerUserNoModel.put("PRONO", power.getString("proNo"));
						powerUserNoModel.put("PROVINCEID", power.getString("provinceId"));
						powerUserNoModel.put("TOTAL_BALANCE", "0");
						powerUserNoModel.put("STATUS", "02");
						powerUserNoModel.put("DESC", "户号积分不足");
						powerUserNoReturn.add(powerUserNoModel);
						continue;
					}


				}
				
				/////////////////////////////////////新账户体系积分数据添加处理开始////////////////////////////////////////
				EcBpAccountIntegralDetail accountIntegralDetail = new EcBpAccountIntegralDetail();
				String detailId=UUIDUtil.getUUID();//明细ID（UUID）返回报文中的业务ID
				
				if(incomeIntegralList.size()>0) {
					//插入积分收入表
					int incomeNum=incomeIntegralMapper.insertList(incomeIntegralList);
					//插入户号账户表
					int consNoNum=consNoIntegralMapper.batchInsertOrUpdate(consNoIntegralList);
					//插入 积分明细表
					accountIntegralDetail.setDetailId(detailId);//明细ID（UUID）
					accountIntegralDetail.setAccountId(accountId);//总账户ID
					accountIntegralDetail.setAccountName(accountName);//账户名称
					accountIntegralDetail.setSerialNo(serialNo);//收支流水号
					accountIntegralDetail.setDealType(NewAccountConstant.DEAL_TYPE_INCOME);//业务方向
					accountIntegralDetail.setBalance(totalBalance);//积分金额
					accountIntegralDetail.setCreateTime(TimeUtil.getDate("YYYYMMddHHmmssSSS"));//创建时间
					accountIntegralDetail.setDealTime(TimeUtil.getDate("YYYYMMddHHmmssSSS"));//交易时间=创建时间
					accountIntegralDetail.setBussDiscrible("01".equals("01")?"积分划转":"缴费积分划转");//业务描述
					accountIntegralDetail.setBussType(NewAccountConstant.BUSS_TYPE_DLJFZR);//业务类型 04:积分划转
					accountIntegralDetail.setAcctDate(TimeUtil.getDate("YYYYMMddHHmmssSSS"));//账务日期
					accountIntegralDetailMapper.insert(accountIntegralDetail);
					//更新 积分账户总表
					//查询账户积分总表,若无,需调用 积分账户新增接口
					EcBpAccountIntegral accountIntegral = accountIntegralMapper.selectIntegralByUnionId(accountId);
					accountIntegral.setCreateTime(TimeUtil.getDate("YYYYMMddHHmmssSSS"));
					accountIntegral.setBalance(accountIntegral.getBalance().add(totalBalance));//总可用积分
					accountIntegralMapper.update(accountIntegral);
				}
				
			
				/////////////////////////////////////新账户体系积分数据添加处理结束////////////////////////////////////////
				// 5、扣减之后调用资产中心新增积分的接口
				JSONObject addjson = new JSONObject();
				addjson.put("BUSINESS_ID", json.get("BUSINESS_ID").toString());
				addjson.put("SOURCE_DESCRIBE", "积分划转");
				addjson.put("INCOME_NUM", totalBalance);
				addjson.put("INCOME_SOURCE", "01");
				addjson.put("OPERATION_STATUS", "01");
				addjson.put("LOGIN_ACCOUNT_ID", json.get("LOGIN_ACCOUNT_ID"));
				JSONObject accountServiceReturn = modifyIntegral(addjson, AccountConstant.AMT_DIRECTION_IN);
				log.info("账户中心添加接口返回参数：{}", accountServiceReturn);
				String resultCode=accountServiceReturn.getString("resultCode");
				if(resultCode.equals("01")){
					accountIntegralDetail.setStatus("1");//同步至资产中心状态（0:失败1:成功）
				}else{
					accountIntegralDetail.setStatus("0");//同步至资产中心状态（0:失败1:成功）
				}
				accountIntegralDetailMapper.update(accountIntegralDetail);
				log.info("积分账户明细表更新成功,流水号:"+serialNo+",同步状态:"+accountServiceReturn.getString("resultCode"));
				//如果资产中心失败，直接返回失败
				if(accountServiceReturn.getString("resultCode").equals(NewAccountConstant.RETURN_CODE_FAIL)){
					return ResultModel.ReturnErrorJson();
				}
			}

			System.out.println("用户点击积分中心划转总积分"+totalBalance);

			JSONObject succesajson=new JSONObject();
			succesajson.put("LOGIN_ACCOUNT_ID", json.getString("LOGIN_ACCOUNT_ID"));
			succesajson.put("STATUS", "02");
			succesajson.put("TRAIN_TIME", new Date());
			succesajson.put("DESCRIBE", "积分划转成功");
			succesajson.put("TOTAL_BALANCE", totalBalance.toString());
			succesajson.put("POWERUSERNOLIST", powerUserNoReturn);
			jsonReturn= JSONObject.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnSucceed(succesajson)));
			log.info("资产中心划转积分返回值=======================》{}",jsonReturn.toJSONString());

		} catch (Exception e) {
			log.error("用户点击积分中心积分划转异常",e.getMessage());
		}
		return jsonReturn;
	}

	/**
	 * 用户点击积分中心积分划转(20181020新接口)
	 * @param jsonObject( PROVINCE_CODE	网省编号
	 *				ORG_NO	供电单位编码
	 *				BUSINESS_TYPE	业务类型
	 *				BUSINESS_ID	业务ID
	 *				LOGIN_ACCOUNT_ID	登录账户ID)
	 * 
	 *            注意： 1、分布式是事务的处理，户号积分扣减成功，但是资产中心积分未增加，要怎么处理。
	 *            2、接口的响应时间，因为此接口提供给用户点击需要提升用户体验。 建议： 1、生成订单、标记状态、跟踪好订单信息 2、异步处理
	 * 
	 * 
	 */
	@Override
	public JSONObject changeIntegralByPower(JSONObject json) {
		// 初始化接口地址
		String TRANSFER_URL = urlConfigUtil.getUrlByKey(RedisKey.URLCON_PREFIXX.getKey(), RedisKey.HOUSE_INTEGRAL_TRANSFER.getKey());
		String QUERY_URL = urlConfigUtil.getUrlByKey(RedisKey.URLCON_PREFIXX.getKey(), RedisKey.HOUSE_INTEGRAL_QUERY.getKey());
		//String QUERY_URL = "http://localhost:10109/house/queryConsBalance";
		JSONObject jsonReturn = null;
		String PROVINCE_CODE = "";// 网省编号
		String ORG_NO = "";// 供电单位编码
		String CONS_NO = "";// 户号
		String BUSINESS_ID = "";// 业务ID
		//		String LOGIN_ACCOUNT_ID = "";//用户id
		//		String LOGIN_ACCOUNT = "";//登录名
		try {

			if(json.containsKey("BUSINESS_ID")) {
				BUSINESS_ID = json.getString("BUSINESS_ID");// 业务ID
			}
			//			if(json.containsKey("LOGIN_ACCOUNT_ID")) {
			//				LOGIN_ACCOUNT_ID = json.getString("LOGIN_ACCOUNT_ID");// 登录账户ID
			//			}
			//			if(json.containsKey("LOGIN_ACCOUNT")) {
			//				LOGIN_ACCOUNT = json.getString("LOGIN_ACCOUNT");// 登录账户
			//			}

			// 2、查询数据库绑定关系中强绑定关系的户号
			//直接获取绑定的户号信息
			JSONArray powerList = (JSONArray) json.get("POWERUSERNOLIST");
			log.info("");
			List<Map<String, String>> powerUserNoReturn= new ArrayList<Map<String,String>>();
			if(powerList!=null&&powerList.size()>0) {
				for (int i=0;i<powerList.size();i++) {
					JSONObject power = powerList.getJSONObject(i);
					if(power.containsKey("provinceId")) {
						PROVINCE_CODE = power.getString("provinceId");// 网省编号
					}else {
						log.info("用户划转省码是空");
					}
					if(power.containsKey("orgNo")) {
						ORG_NO = power.getString("orgNo");//供电单位编码
					}else {
						log.info("用户划转供电编码是空");
					}

					if(power.containsKey("consNo")) {
						CONS_NO = power.getString("consNo");//供电单位编码
					}else {
						log.info("用户划转户号是空");
					}
					//3、根据户号查询户号上得积分
					//					QUERY_URL = "http://localhost:10109/house/queryConsBalance";
					String jsonQueryResult=queryConsBalance(QUERY_URL, CONS_NO, PROVINCE_CODE, ORG_NO);
					log.info("查询户号积分========================》{}",jsonQueryResult);
					//以后自建和统一积分都走这里
					//String jsonQueryResult=queryConsBalanceByInner(QUERY_URL, e.getPowerUserNo(), PROVINCE_CODE, ORG_NO,LOGIN_ACCOUNT_ID,LOGIN_ACCOUNT);
					JSONObject jsonQuery=JSONObject.parseObject(jsonQueryResult);
					if(!"0".equals(jsonQuery.get("code").toString())) {
						continue;
						//return jsonQuery;
					}
					JSONObject jsoncontent=JSONObject.parseObject(jsonQuery.get("content").toString());
					//可用余额大于零调用资产中新增接口
					if (((Integer)jsoncontent.get("BALANCE")>0)) {
						//4、根据户号查询的结果扣减户号上所有的积分余额
						String jsonDedConsBalanceResult=dedConsBalance(TRANSFER_URL, PROVINCE_CODE, ORG_NO, CONS_NO,BUSINESS_ID, "01", "01", jsoncontent.get("BALANCE").toString());
						JSONObject jsonDedCons=JSONObject.parseObject(jsonDedConsBalanceResult);
						if(!"0".equals(jsonDedCons.get("code").toString())) {
							continue;
							//return jsonDedCons;
						}
						Map<String, String> powerUserNoModel = new HashMap<>();
						powerUserNoModel.put("POWER_USER_NO", CONS_NO);
						powerUserNoModel.put("TOTAL_BALANCE", jsoncontent.get("BALANCE").toString());
						powerUserNoReturn.add(powerUserNoModel);
						// 5、扣减之后调用资产中心新增积分的接口
						JSONObject addjson = new JSONObject();
						addjson.put("BUSINESS_ID", json.get("BUSINESS_ID").toString());
						addjson.put("SOURCE_DESCRIBE", "积分划转");
						addjson.put("INCOME_NUM", jsoncontent.get("BALANCE").toString());
						addjson.put("INCOME_SOURCE", "01");
						addjson.put("OPERATION_STATUS", "01");
						addjson.put("LOGIN_ACCOUNT_ID", json.get("LOGIN_ACCOUNT_ID"));
						JSONObject accountServiceReturn = modifyIntegral(addjson, AccountConstant.AMT_DIRECTION_IN);
						log.info("账户中心添加接口返回参数：{}", accountServiceReturn);
						if (!"01".equals(accountServiceReturn.get("resultCode").toString())) {
							//							HOUSE_INTEGRAL_ADD
							continue;
							//return JSONObject.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnError(AccountReturn.ASSETHUB_ERROR_ADD)));
						}

					}else {
						Map<String, String> powerUserNoModel = new HashMap<>();
						powerUserNoModel.put("POWER_USER_NO", CONS_NO);
						powerUserNoModel.put("TOTAL_BALANCE", jsoncontent.get("BALANCE").toString());
						powerUserNoReturn.add(powerUserNoModel);
						continue;
						//return JSONObject.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnError(AccountReturn.HOUSE_DED_BALANCE_ZERO)));
					}



				}


			}


			JSONObject succesajson=new JSONObject();
			succesajson.put("LOGIN_ACCOUNT_ID", json.getString("LOGIN_ACCOUNT_ID"));
			succesajson.put("STATUS", "02");
			succesajson.put("TRAIN_TIME", new Date());
			succesajson.put("DESCRIBE", "积分划转成功");
			succesajson.put("POWERUSERNOLIST", powerUserNoReturn);
			jsonReturn= JSONObject.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnSucceed(succesajson)));
			log.info("资产中心划转积分返回值=======================》{}",jsonReturn.toJSONString());

		} catch (Exception e) {
			log.error("用户点击积分中心积分划转异常",e.getMessage());
		}
		return jsonReturn;
	}








	/**
	 * 用户点击积分中心积分划转
	 * @param jsonObject( PROVINCE_CODE	网省编号
	 *				ORG_NO	供电单位编码
	 *				BUSINESS_TYPE	业务类型
	 *				BUSINESS_ID	业务ID
	 *				LOGIN_ACCOUNT_ID	登录账户ID)
	 * 
	 *            注意： 1、分布式是事务的处理，户号积分扣减成功，但是资产中心积分未增加，要怎么处理。
	 *            2、接口的响应时间，因为此接口提供给用户点击需要提升用户体验。 建议： 1、生成订单、标记状态、跟踪好订单信息 2、异步处理
	 * 
	 * 
	 */
	public JSONObject changeIntegral(JSONObject json) {
		// 初始化接口地址
		String TRANSFER_URL = urlConfigUtil.getUrlByKey(RedisKey.URLCON_PREFIXX.getKey(), RedisKey.HOUSE_INTEGRAL_TRANSFER.getKey());
		String QUERY_URL = urlConfigUtil.getUrlByKey(RedisKey.URLCON_PREFIXX.getKey(), RedisKey.HOUSE_INTEGRAL_QUERY.getKey());
		//String QUERY_URL = "http://localhost:10109/house/queryConsBalance";
		JSONObject jsonReturn = null;
		String PROVINCE_CODE = "";// 网省编号
		String ORG_NO = "";// 供电单位编码
		String BUSINESS_ID = "";// 业务ID
		String LOGIN_ACCOUNT_ID = "";//用户id
		String LOGIN_ACCOUNT = "";//登录名
		if(json.containsKey("PROVINCE_CODE")) {
			PROVINCE_CODE = json.getString("PROVINCE_CODE");// 网省编号
		}
		if(json.containsKey("ORG_NO")) {
			ORG_NO = json.getString("ORG_NO");//供电单位编码
		}
		if(json.containsKey("BUSINESS_ID")) {
			BUSINESS_ID = json.getString("BUSINESS_ID");// 业务ID
		}
		if(json.containsKey("LOGIN_ACCOUNT_ID")) {
			LOGIN_ACCOUNT_ID = json.getString("LOGIN_ACCOUNT_ID");// 登录账户ID
		}
		if(json.containsKey("LOGIN_ACCOUNT")) {
			LOGIN_ACCOUNT = json.getString("LOGIN_ACCOUNT");// 登录账户
		}

		//用户点击积分中心积分划转成功之后,向老数据库插入数据到积分流水明细表(EC_BP_MEMBERDETAIL)   后期废除
		/*	EcBpMemberDetail ecBpMemberDetail = new EcBpMemberDetail();
		ecBpMemberDetail.setDetailId(UUIDUtil.getUUID());
		ecBpMemberDetail.setMemberId(json.getString("LOGIN_ACCOUNT_ID"));
		ecBpMemberDetail.setBpValue(1000000);
		ecBpMemberDetail.setCreateTime(new Date());
		ecBpMemberDetail.setOriginId(BUSINESS_ID);
		ecBpMemberDetail.setOriginRemark("点击积分中心赠送积分");
		ecBpMemberDetail.setBpValueRemain(1000000);
		ecBpMemberDetail.setBpChangeType("0");
		ecBpMemberDetail.setVersion(1);
		ecBpMemberDetail.setProvinceId(json.getString(PROVINCE_CODE));
		ecBpMemberDetail.setStartTime(TimeUtil.stringToDate("2018-10-05 11:11:11", "yyyy-MM-dd HH:mm:ss"));
		ecBpMemberDetail.setEndTime(TimeUtil.stringToDate("2028-10-05 11:11:11", "yyyy-MM-dd HH:mm:ss"));
		ecBpMemberDetail.setBpIsFrozen("0");//未冻结
		ecBpMemberDetailMapper.insertMemberDetail(ecBpMemberDetail);*/

		try {
			// 2、查询数据库绑定关系中强绑定关系的户号
			// 获取绑定户号list
			Map<String,Object> map=new HashMap<>();
			map.put("AccountId", LOGIN_ACCOUNT_ID);
			map.put("PowerUserNo","");
			List<EcBpTransferBinding> powerUserNoList = ecBpTransferBindingMapper.selectByAccountId(map);
			if (!(powerUserNoList.size() > 0)) {
				log.error("用户无绑定户号不需要划转");
				return JSONObject.parseObject(
						JsonUtil.bean2json(ResultModel.AccountReturnError(AccountReturn.TRANSFER_BINDING_ERROR_NULL)));
			}
			log.info("查询绑定户号信息：{}",powerUserNoList.toString());
			List<Map<String, String>> powerUserNoReturn= new ArrayList<Map<String,String>>();
			for(EcBpTransferBinding e:powerUserNoList){
				//判断强绑定
				if (AccountConstant.BINDING_HZRZ.equals(e.getBindingStatus())||AccountConstant.BINDING_ZDBD.equals(e.getBindingStatus())) {
					//3、根据户号查询户号上得积分
					if(e.getProvinceId()!=null||!"".equals(e.getProvinceId())) {
						PROVINCE_CODE=e.getProvinceId();
					}
					if(e.getOrgNo()!=null||!"".equals(e.getOrgNo())) {
						ORG_NO=e.getOrgNo();
					}
					String jsonQueryResult=queryConsBalance(QUERY_URL, e.getPowerUserNo(), PROVINCE_CODE, ORG_NO);
					//以后自建和统一积分都走这里
					//					String jsonQueryResult=queryConsBalanceByInner(QUERY_URL, e.getPowerUserNo(), PROVINCE_CODE, ORG_NO,LOGIN_ACCOUNT_ID,LOGIN_ACCOUNT);

					JSONObject jsonQuery=JSONObject.parseObject(jsonQueryResult);
					if(!"0".equals(jsonQuery.get("code").toString())) {
						continue;
						//return jsonQuery;
					}
					JSONObject jsoncontent=JSONObject.parseObject(jsonQuery.get("content").toString());
					//可用余额大于零调用资产中新增接口
					if (((Integer)jsoncontent.get("BALANCE")>0)) {
						//4、根据户号查询的结果扣减户号上所有的积分余额
						String jsonDedConsBalanceResult=dedConsBalance(TRANSFER_URL, PROVINCE_CODE, ORG_NO, e.getPowerUserNo(),BUSINESS_ID, "01", "01", jsoncontent.get("BALANCE").toString());
						JSONObject jsonDedCons=JSONObject.parseObject(jsonDedConsBalanceResult);
						if(!"0".equals(jsonDedCons.get("code").toString())) {
							continue;
							//return jsonDedCons;
						}
						Map<String, String> powerUserNoModel = new HashMap<>();
						powerUserNoModel.put("POWER_USER_NO", e.getPowerUserNo());
						powerUserNoModel.put("TOTAL_BALANCE", jsoncontent.get("BALANCE").toString());
						powerUserNoReturn.add(powerUserNoModel);
						// 5、扣减之后调用资产中心新增积分的接口
						JSONObject addjson = new JSONObject();
						addjson.put("BUSINESS_ID", json.get("BUSINESS_ID").toString());
						addjson.put("SOURCE_DESCRIBE", "积分划转");
						addjson.put("INCOME_NUM", jsoncontent.get("BALANCE").toString());
						addjson.put("INCOME_SOURCE", "01");
						addjson.put("OPERATION_STATUS", "01");
						addjson.put("LOGIN_ACCOUNT_ID", json.get("LOGIN_ACCOUNT_ID"));
						addjson.put("USER_NAME",  AtbashUtils.encrypt(json.getString("USER_NAME")));
						addjson.put("IP", json.getString("IP"));
						addjson.put("CHANNEL_RESOURCE", json.getString("CHANNEL_RESOURCE"));
						JSONObject accountServiceReturn = modifyIntegral(addjson, AccountConstant.AMT_DIRECTION_IN);
						log.info("账户中心添加接口返回参数：{}", accountServiceReturn);
						if (!"01".equals(accountServiceReturn.get("resultCode").toString())) {
							continue;
							//return JSONObject.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnError(AccountReturn.ASSETHUB_ERROR_ADD)));
						}

					}else {
						Map<String, String> powerUserNoModel = new HashMap<>();
						powerUserNoModel.put("POWER_USER_NO", e.getPowerUserNo());
						powerUserNoModel.put("TOTAL_BALANCE", jsoncontent.get("BALANCE").toString());
						powerUserNoReturn.add(powerUserNoModel);
						continue;
						//return JSONObject.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnError(AccountReturn.HOUSE_DED_BALANCE_ZERO)));
					}
				} else {
					log.info("用户绑定户号不是强绑定关系");
				}
			}

			JSONObject succesajson=new JSONObject();
			succesajson.put("LOGIN_ACCOUNT_ID", json.getString("LOGIN_ACCOUNT_ID"));
			succesajson.put("STATUS", "02");
			succesajson.put("TRAIN_TIME", new Date());
			succesajson.put("DESCRIBE", "积分划转成功");
			succesajson.put("POWERUSERNOLIST", powerUserNoReturn);
			jsonReturn= JSONObject.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnSucceed(succesajson)));

		} catch (Exception e) {
			log.error("用户点击积分中心积分划转异常");
		}
		return jsonReturn;
	}

	/**
	 * 账户中心查询积分余额
	 * 
	 * @author zhangjiajia
	 * @param jsonObject(
	 *            ASSET_TYPE 资产类型 REQUEST_ID 唯一随机id REQUEST_TIME 请求时间 SIGN_DATA
	 *            签名 REMARK 备注 UNIONID 用户ID )
	 */
	@Override
	public JSONObject queryIntegral(JSONObject json){
		JSONObject resultJson=new JSONObject();
		//拼接请求参数
		//header头部
		Map<String, String> headerMap=new HashMap<String, String>();
		headerMap.put("IP",json.getString("IP"));
		headerMap.put("CHANNEL_RESOURCE","5");//渠道编码
		headerMap.put("USER_NAME",json.getString("USER_NAME"));//渠道编码
		//data
		Map<String, String> dataMap=new HashMap<String, String>();
		dataMap.put("ASSET_TYPE", AccountConstant.ASSET_TYPE);//01充值卡02卡券03 积分
		dataMap.put("REQUEST_ID", UUIDGenerator.getInstance().getReplaceNotMd5UUID());
		dataMap.put("REQUEST_TIME", TimeUtil.getDate("yyyyMMddHHmmssSSS"));
		dataMap.put("UNIONID",json.getString("LOGIN_ACCOUNT_ID"));//账户ID
		dataMap.put("USER_NAME", AtbashUtils.encrypt(json.getString("USER_NAME")));
		dataMap.put("SIGN_DATA", json.getString("LOGIN_ACCOUNT_ID")+"|"+AccountConstant.ASSET_TYPE+"|"+json.getString("CHANNEL_RESOURCE"));
		//获取接口地址
		String url=urlConfigUtil.getUrlByKey(RedisKey.URLCON_PREFIXX.getKey(), RedisKey.ZCZX_INTEGRAL_QUERY.getKey());;
		if (StringUtil.isNull(url)) {
			log.error("配置资产中心接口为空");
			return JSONObject.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnError(AccountReturn.EC_BP_ASSETHUB_CONFIG_ERROR_URLADDRESS)));
		}
		//调用资产中心
		JSONObject result = JSONObject.parseObject(DebAsetHttpUtil.sendPost(url,headerMap, dataMap,null));

		if(AccountConstant.REPCD_SUCCESS.equals(result.getJSONObject("header").getString("repcd"))
				&&AccountConstant.RESULT_CODE_SUCCESS.equals(result.getJSONObject("data").getString("RESULT_CODE"))){
			log.info("资产中心处理成功");
			JSONObject resData=result.getJSONObject("data");
			resultJson.put("ACCOUNT_NAME", json.getString("ACCOUNT_NAME"));//账户名称
			resultJson.put("LOGIN_ACCOUNT_ID", json.getString("LOGIN_ACCOUNT_ID"));//登录账户ID
			resultJson.put("ACCOUNT_STATUS", "01");//账户状态01：正常02：锁定03：注销04：冻结05：只收不付
			resultJson.put("CONSUMER_STATUS", "1");//客户类型1：一般用电客户2：企业用电客户3：内部客户 default：1
			resultJson.put("BALANCE", resData.getString("ENABLE_NUMBER"));//可用余额
			resultJson.put("TOTAL_BALANCE", resData.getString("CURRENT_NUMBER"));//积分余额
			return ResultModel.ReturnSucceedJson(resultJson);
		}else{
			log.info("资产中心处理失败："+result.getJSONObject("header").getString("repmsg"));
			return JSONObject.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnError(AccountReturn.ASSETHUB_ERROR_QUERY)));
		}
	}

	/**
	 * 账户中心扣减接口
	 * 
	 * @param jsonObject(USER_NAME
	 *            账户名称 LOGIN_ACCOUNT_ID 登录账户ID OPERATION_STATUS 操作类型
	 *            EXPENDITURE_WHERE 业务类型 EXPENDITURE_DESCRIBE 支出备注
	 *            EXPENDITURE_NUM 支出金额 WHEREABOUTS_ID 去向方账号)
	 * @author zw
	 * @return
	 * @throws Exception
	 */
	public JSONObject deductionIntegral(JSONObject jsonObject) {
		try {
			String userName = jsonObject.getString("USER_NAME");
			userName = AtbashUtils.encrypt(userName);
			jsonObject.put("USER_NAME", userName);
			JSONObject resultJson = modifyIntegral(jsonObject, AccountConstant.AMT_DIRECTION_OUT);

			JSONObject returncontent=new JSONObject();
			returncontent.put("BUSINESS_ID",jsonObject.getString("BUSINESS_ID"));
			returncontent.put("LOGIN_ACCOUNT_ID", jsonObject.getString("LOGIN_ACCOUNT_ID"));
			returncontent.put("STATUS", "02");
			returncontent.put("DESCRIBE", resultJson.getString("resultMsg"));
			//入库
			EcBpAssethubIntegral ecBpAssethubIntegral = new EcBpAssethubIntegral();

			ecBpAssethubIntegral.setId(jsonObject.getString("BUSINESS_ID"));
			ecBpAssethubIntegral.setAssethubDesc(jsonObject.getString("EXPENDITURE_DESCRIBE"));
			ecBpAssethubIntegral.setAssethubStatus(resultJson.getString("resultCode"));
			ecBpAssethubIntegral.setUnionid(jsonObject.getString("LOGIN_ACCOUNT_ID"));
			ecBpAssethubIntegral.setIntegralType(AccountConstant.INTEGRAL_DED);
			ecBpAssethubIntegral.setAssetType(AccountConstant.ASSET_TYPE);
			ecBpAssethubIntegral.setIntegral(jsonObject.getBigDecimal("EXPENDITURE_NUM"));
			ecBpAssethubIntegral.setCreateTime(new Date());
			int insertAssethubIntegralStatus = ecBpAssethubIntegralMapper.insertSelective(ecBpAssethubIntegral);
			if (!AccountConstant.ASSETHTB_STATUS_SUCCESS.equals(resultJson.getString("resultCode"))) {
				log.error("资产中心积分扣减失败");
				return JSONObject
						.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnError(AccountReturn.ASSETHUB_ERROR_DEDUCTION)));
			}
			//账户中心扣减接口的应答域
			if (insertAssethubIntegralStatus == 1) {
				log.info("积分扣减变更记录入库成功");
				return ResultModel.ReturnSucceedJson(returncontent);
			} else {
				log.error("积分扣减变更记录入库失败");
				return JSONObject.parseObject(
						JsonUtil.bean2json(ResultModel.AccountReturnError(AccountReturn.ASSETHUB_INTEGRAL_ERROR)));
			}

		} catch (Exception e) {
			log.error("积分扣减失败：{}", e.toString());
			return JSONObject.parseObject(
					JsonUtil.bean2json(ResultModel.AccountReturnError(AccountReturn.ACCOUNT_ERROR)));
		}
	}

	/**
	 * 账户中心添加接口
	 *
	 * @param jsonObject 
	 * @return
	 * @throws Exception
	 */
	public JSONObject addIntegral(JSONObject jsonObject) {
		try {
			String userName = jsonObject.getString("USER_NAME");
			userName = AtbashUtils.encrypt(userName);
			jsonObject.put("USER_NAME", userName);
			JSONObject resultJson = modifyIntegral(jsonObject, AccountConstant.AMT_DIRECTION_IN);
			EcBpAssethubIntegral ecBpAssethubIntegral = new EcBpAssethubIntegral();
			ecBpAssethubIntegral.setId(jsonObject.getString("BUSINESS_ID"));
			ecBpAssethubIntegral.setUnionid(jsonObject.getString("LOGIN_ACCOUNT_ID"));
			ecBpAssethubIntegral.setIntegral(jsonObject.getBigDecimal("INCOME_NUM"));
			ecBpAssethubIntegral.setAssetType(AccountConstant.ASSET_TYPE);
			ecBpAssethubIntegral.setAssethubDesc(jsonObject.getString("SOURCE_DESCRIBE"));
			ecBpAssethubIntegral.setAssethubStatus(resultJson.getString("resultCode"));
			ecBpAssethubIntegral.setIntegralType(AccountConstant.INTEGRAL_ADD);
			ecBpAssethubIntegral.setCreateTime(new Date());
			int insertAssethubIntegralStatus = ecBpAssethubIntegralMapper.insertSelective(ecBpAssethubIntegral);
			//账户中心添加接口的应答域
			JSONObject successjson = new JSONObject();
			successjson.put("ACCOUNT_MAIN_ID", jsonObject.getString("BUSINESS_ID"));
			successjson.put("LOGIN_ACCOUNT_ID", jsonObject.getString("LOGIN_ACCOUNT_ID"));
			successjson.put("STATUS", "02");
			successjson.put("DESCRIBE", "积分增加成功");

			if (!AccountConstant.ASSETHTB_STATUS_SUCCESS.equals(resultJson.getString("resultCode"))) {
				return JSONObject
						.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnError(AccountReturn.ASSETHUB_ERROR_ADD)));
			}

			if (insertAssethubIntegralStatus == 1) {
				log.info("积分增加变更记录入库成功");
				return ResultModel.ReturnSucceedJson(successjson);
			} else {
				log.error("积分增加变更记录入库失败");
				return JSONObject.parseObject(
						JsonUtil.bean2json(ResultModel.AccountReturnError(AccountReturn.ASSETHUB_INTEGRAL_ERROR)));
			}
		} catch (Exception e) {
			log.error("积分增加失败：{}", e.toString());
			return JSONObject.parseObject(
					JsonUtil.bean2json(ResultModel.AccountReturnError(AccountReturn.ACCOUNT_ERROR)));
		}
	}

	/**
	 * 用户绑定关系同步
	 * 
	 * @param json(BUSINESS_ID 业务ID LOGIN_ACCOUNT_ID 登录账户ID POWER_USER_NO 户号ID
	 *        IS_BOUND 绑定关系 BOUND_TIME 绑定时间)
	 * @return
	 */
	@Override
	public JSONObject bindingSync(JSONObject json) {
		//前置接口传过来的boundWay绑定方式  01=自动绑定，02=手动绑定，03=户主绑定 00解绑
		//祥龙绑定表对应状态01=户主认证，02=手动绑定，03=自动绑定00=解绑
		JSONObject result = null;
		Date date = new Date();
		String provinceid=json.getString("PROVINCE_ID");
		JSONObject returnjson = new JSONObject();
		returnjson.put("BUSINESS_ID", json.getString("BUSINESS_ID"));
		returnjson.put("LOGIN_ACCOUNT_ID", json.getString("LOGIN_ACCOUNT_ID"));
		returnjson.put("CREATE_TEIME", date);
		ProvinceCodeEnums[] enums = ProvinceCodeEnums.values();
		for (ProvinceCodeEnums ProvinceCode : enums) {
			if(json.getString("PROVINCE_ID").length()>=6) {
				if(json.getString("PROVINCE_ID").equals(ProvinceCode.getLongCode())) {
					provinceid=ProvinceCode.getShortCode();
					break;
				}
			}else {
				provinceid=json.getString("PROVINCE_ID");
				break;
			}

		}
		//对应祥龙的状态
		String bindingStatus=json.getString("IS_BOUND");
		if("01".equals(json.getString("IS_BOUND"))){
			bindingStatus="03";
		}else if("03".equals(json.getString("IS_BOUND"))) {
			bindingStatus="01";	
		}
		//手动绑定02不保存直接返回
		if(AccountConstant.BINDING_SDBD.equals(json.getString("IS_BOUND"))) {
			log.info("用户手动绑定关系不需要入库");
			returnjson.put("DESCRIBE", "用户手动绑定关系不需要入库");
			result = JSONObject.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnSucceed(returnjson)));
			return returnjson;
		}
		// 获取绑定户号list
		Map<String,Object> map=new HashMap<>();
		map.put("AccountId", json.getString("LOGIN_ACCOUNT_ID"));
		map.put("PowerUserNo",json.getString("POWER_USER_NO"));
		List<EcBpTransferBinding> powerUserNoList = ecBpTransferBindingMapper.selectByAccountId(map);
		//判断userid和户号是否存在
		if(powerUserNoList.size()>0) {
			//判断数据是否有改动
			if(!powerUserNoList.get(0).getBindingStatus().equals(bindingStatus)) {
				EcBpTransferBinding ecBpTransferBinding = new EcBpTransferBinding();
				ecBpTransferBinding.setAccountId(json.getString("LOGIN_ACCOUNT_ID"));
				ecBpTransferBinding.setPowerUserNo(json.getString("POWER_USER_NO"));
				ecBpTransferBinding.setBindingStatus(bindingStatus);
				int insertreturn =ecBpTransferBindingMapper.updateByPrimaryKeySelective(ecBpTransferBinding);
				if (insertreturn>0) {
					log.info("用户绑定关系同步状态更新成功");
					returnjson.put("DESCRIBE", "用户绑定关系同步状态更新成功");
					result = JSONObject.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnSucceed(returnjson)));
				} else {
					log.info("用户绑定关系同步状态更新失败");
					returnjson.put("DESCRIBE", "用户绑定关系同步状态更新失败");
					result = JSONObject.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnError(returnjson)));
				}
				return result;
			}
			returnjson.put("DESCRIBE", "用户绑定关系未发生变动");
			result = JSONObject.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnSucceed(returnjson)));
			return result;

		}else {
			EcBpTransferBinding ecBpTransferBinding = new EcBpTransferBinding();
			ecBpTransferBinding.setAccountId(json.getString("LOGIN_ACCOUNT_ID"));
			ecBpTransferBinding.setBindingDesc("统一账户用户同步");
			ecBpTransferBinding.setBindingStatus(bindingStatus);
			ecBpTransferBinding.setBusinessId(json.getString("BUSINESS_ID"));
			ecBpTransferBinding.setCreateTime(date);
			if("".equals(json.getString("BOUND_TIME"))||json.getString("BOUND_TIME")==null||json.containsKey("BOUND_TIME")) {
				ecBpTransferBinding.setCallTime(date);
			}else {
				ecBpTransferBinding.setCallTime(TimeUtil.stringToDate(json.getString("BOUND_TIME"), "yyyy-MM-dd HH:mm:ss"));
			}

			ecBpTransferBinding.setTransferId(UUIDGenerator.getInstance().getReplaceNotMd5UUID());
			ecBpTransferBinding.setProvinceId(provinceid);
			ecBpTransferBinding.setOrgNo(json.getString("ORG_NO"));
			ecBpTransferBinding.setPowerUserNo(json.getString("POWER_USER_NO"));
			int insertreturn = ecBpTransferBindingMapper.insertSelective(ecBpTransferBinding);
			if (insertreturn == 1) {
				log.info("用户绑定关系同步入库成功");
				returnjson.put("DESCRIBE", "用户绑定关系同步成功");
				result = JSONObject.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnSucceed(returnjson)));
			} else {
				log.info("用户绑定关系同步入库失败");
				returnjson.put("DESCRIBE", "用户绑定关系同步失败");
				result = JSONObject.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnError(returnjson)));
			}
			return result;
		}

	}

	/**
	 * 调用查询户号余额接口
	 * 
	 * @param url           接口地址
	 * @param POWER_USER_NO 户号
	 * @param PROVINCE_CODE 网省编码
	 * @param ORG_NO        供电单位编码
	 * @return
	 */
	private  String queryConsBalance(String url, String POWER_USER_NO, String PROVINCE_CODE, String ORG_NO) {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("POWER_USER_NO", POWER_USER_NO);
		jsonObject.put("PROVINCE_CODE", PROVINCE_CODE);
		jsonObject.put("ORG_NO", ORG_NO);
		//		jsonObject.put("ORGNO", ORGNO);
		//		jsonObject.put("CONSNO", CONSNO);
		//		jsonObject.put("USERID", USERID);
		//		jsonObject.put("LOGIN_ACCOUNT", LOGIN_ACCOUNT);
		log.info("【户号中心】查询：URL：{}",url);
		log.info("【户号中心】查询：请求参数：{}",jsonObject);
		String jsonQueryResult = RequestUtils.sendPost(url, jsonObject.toString());
		log.info("【户号中心】查询：返回参数：{}",jsonQueryResult);
		return jsonQueryResult;

	}

	/**
	 * 调用查询户号余额接口（自建网省）
	 * 
	 * @param url           接口地址
	 * @param POWER_USER_NO 户号
	 * @param PROVINCE_CODE 网省编码
	 * @param ORG_NO        供电单位编码
	 * @param USERID        用户id
	 * @param LOGINACCOUNT  登录名
	 * @return
	 */
	private  String queryConsBalanceByInner(String url, String POWER_USER_NO, String PROVINCE_CODE, String ORG_NO,String LOGIN_ACCOUNT_ID,String LOGINACCOUNT,String kaiguan) {
		JSONObject jsonObject = new JSONObject();
		String jsonQueryResult = null;
		try {
			//			jsonObject.put("POWER_USER_NO", POWER_USER_NO);
			jsonObject.put("ORGNO", PROVINCE_CODE);
			jsonObject.put("CONSNO", POWER_USER_NO);
			jsonObject.put("USERID", LOGIN_ACCOUNT_ID);
			jsonObject.put("LOGIN_ACCOUNT", LOGINACCOUNT);
			jsonObject.put("KAIGUAN", kaiguan);
			log.info("【内网转化中心】查询：URL：{}",url);
			log.info("【内网转化中心】查询：请求参数：{}",jsonObject);
			//			jsonQueryResult = RequestUtils.sendPost(url, jsonObject.toString());
			jsonQueryResult =invokeBuildOuterService.queryIntegral(jsonObject).toJSONString();
			log.info("【内网转化中心】查询：返回参数：{}",jsonQueryResult);
		} catch (Exception e) {
			// TODO: handle exception
			log.error("【内网转化中心 conversion-inner】查询异常 错误信息={}",e.getMessage());
		}

		return jsonQueryResult;

	}




	/**
	 * 调用扣减户号余额接口
	 * 
	 * @param url
	 * @param PROVINCE_CODE   网上编号
	 * @param ORG_NO          供电单位编码
	 * @param POWER_USER_NO   户号ID
	 * @param ACCOUNT_MAIN_ID 业务ID
	 * @param INCOME_SOURCE   收入来源
	 * @param INCOME_TYPE     操作类型
	 * @param INCOME_NUM      收入总金额
	 * @return
	 */
	private  String dedConsBalance(String url, String PROVINCE_CODE, String ORG_NO, String POWER_USER_NO,
			String ACCOUNT_MAIN_ID, String INCOME_SOURCE, String INCOME_TYPE, String INCOME_NUM) {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("PROVINCE_CODE", PROVINCE_CODE);
		jsonObject.put("ACCOUNT_MAIN_ID", ACCOUNT_MAIN_ID);
		jsonObject.put("ORG_NO", ORG_NO);
		jsonObject.put("POWER_USER_NO", POWER_USER_NO);
		jsonObject.put("INCOME_SOURCE", INCOME_SOURCE);
		jsonObject.put("INCOME_TYPE", INCOME_TYPE);
		jsonObject.put("INCOME_NUM", INCOME_NUM);
		jsonObject.put("STATE_TINE", new Date());
		log.info("【户号中心扣减】URL：{}",url);
		log.info("【户号中心扣减】请求参数：{}",jsonObject);
		String jsonQueryResult = RequestUtils.sendPost(url, jsonObject.toString());
		log.info("【户号中心扣减】返回参数：{}",jsonQueryResult);
		return jsonQueryResult;
	}
	/**
	 * 调用自建网省划转
	 * 
	 * @param url
	 * @param PROVINCE_CODE   网上编号
	 * @param ORG_NO          供电单位编码
	 * @param POWER_USER_NO   户号ID
	 * @param ACCOUNT_MAIN_ID 业务ID
	 * @param INCOME_SOURCE   收入来源
	 * @param INCOME_TYPE     操作类型
	 * @param INCOME_NUM      收入总金额
	 * @param USERID     用户id
	 * @param ACCOUNT_NAME     用户名
	 * @return
	 */
	private  String dedConsBalanceByInner(String url, String PROVINCE_CODE, String ORG_NO, String POWER_USER_NO,
			String ACCOUNT_MAIN_ID, String INCOME_SOURCE, String INCOME_TYPE, String INCOME_NUM,String USERID,String ACCOUNT_NAME,String kaiguan,String CHECKINGID) {
		//{"ORGNO":"33101","CONSNO":"1313706203","USERID":"00099096","LOGIN_ACCOUNT":"ssssss","SCORE":"1","GOLDCOIN":"1"}
		JSONObject jsonObject = new JSONObject();
		//		jsonObject.put("PROVINCE_CODE", PROVINCE_CODE);
		//		jsonObject.put("ACCOUNT_MAIN_ID", ACCOUNT_MAIN_ID);
		//		jsonObject.put("ORG_NO", ORG_NO);
		//		jsonObject.put("POWER_USER_NO", POWER_USER_NO);
		//		jsonObject.put("INCOME_SOURCE", INCOME_SOURCE);
		//		jsonObject.put("INCOME_TYPE", INCOME_TYPE);
		//		jsonObject.put("INCOME_NUM", INCOME_NUM);
		//		jsonObject.put("STATE_TINE", new Date());
		jsonObject.put("ORGNO", PROVINCE_CODE);
		jsonObject.put("CONSNO", POWER_USER_NO);
		jsonObject.put("USERID", USERID);
		jsonObject.put("LOGIN_ACCOUNT", ACCOUNT_NAME);
		jsonObject.put("SCORE", INCOME_NUM);
		jsonObject.put("GOLDCOIN", INCOME_NUM);
		jsonObject.put("KAIGUAN", kaiguan);
		jsonObject.put("CHECKINGID", CHECKINGID);
		log.info("【调用自建网省划转】URL：{}",url);
		log.info("【调用自建网省划转】请求参数：{}",jsonObject);
		//		String jsonQueryResult = RequestUtils.sendPost(url, jsonObject.toString());
		String jsonQueryResult = invokeBuildOuterService.conversionIntegral(jsonObject).toJSONString();
		log.info("【调用自建网省划转】返回参数：{}",jsonQueryResult);
		return jsonQueryResult;
	}


	/**
	 * 用户绑定关系查询
	 * 
	 * @param
	 * @return
	 */
	@Override
	public JSONObject queryAccountBind(JSONObject json) {
		// TODO Auto-generated method stub
		log.info("用户绑定关系查询接口=======================》开始《===================参数：{}", json);
		JSONObject result = null;
		try {
			// 1、校验参数
			if (StrUtil.isEmpty(json.toString())) {
				// 参数为空
				return null;
			}
			// 2、请求统一用户
			String url = urlConfigUtil.getUrlByKey(RedisKey.URLCON_PREFIXX.getKey(),
					RedisKey.USER_CENTER_QUERY.getKey());
			//			String jsonStr = RequestUtils.sendPost(url, json.toString());
			String jsonStr = "{'srvrt':'0000','resultMessage':'返回成功','resultCode':'0000','timeStamp':'11232165446','timeStamp':'powerUserList',"
					+ "'bizrt':{'powerUserList':[{'orgNo':'123456478','provinceId':'123456','elecTypeCode':'01','proNo':'12345','bindType':'1','consNo':'56546121'},"
					+ "{'orgNo':'123456478','provinceId':'123456','elecTypeCode':'01','proNo':'12345','bindType':'1','consNo':'56546121'}]}}";

			// 3、返回结果
			result = JSONObject.parseObject(jsonStr);

		} catch (Exception e) {
			// TODO: handle exception
			log.error("用户绑定关系查询接口异常：错误信息{}", e.toString());
		}
		log.info("用户绑定关系查询接口=======================》结束《===================参数：{},结果：{}", json, result);

		return result;
	}

	/**
	 * 账户中心查询积分明细接口
	 * @param json
	 * @return
	 */
	public JSONObject queryIntegralDetail(JSONObject json){
		JSONObject resultJson=new JSONObject();
		//拼接请求参数
		//header头部
		Map<String, String> headerMap=new HashMap<String, String>();
		headerMap.put("IP",json.getString("IP"));
		//		headerMap.put("CHANNEL_RESOURCE",json.getString("CHANNEL_RESOURCE"));//渠道编码
		headerMap.put("CHANNEL_RESOURCE","5");//渠道编码
		headerMap.put("USER_NAME","");//渠道编码
		//data
		Map<String, String> dataMap=new HashMap<String, String>();
		dataMap.put("ASSET_TYPE", AccountConstant.ASSET_TYPE);//01充值卡02卡券03 积分
		dataMap.put("REQUEST_ID", UUIDGenerator.getInstance().getReplaceNotMd5UUID());
		dataMap.put("REQUEST_TIME", TimeUtil.getDate("yyyyMMddHHmmssSSS"));
		dataMap.put("UNIONID",json.getString("UNION_ID"));//账户ID
		if(!StringUtil.isNull(json.getString("AMT_DIRECTION"))){
			dataMap.put("AMT_DIRECTION",json.getString("AMT_DIRECTION"));//业务方向0出1入
		}
		dataMap.put("PAGEINDEX",json.getString("PAGE_INDEX"));//页码
		dataMap.put("SIGN_DATA", json.getString("UNION_ID")+"|"+AccountConstant.ASSET_TYPE+"|"+json.getString("CHANNEL_RESOURCE"));
		//获取接口地址
		//String url="http://10.1.20.30:8082/assetcontroller/rest/userintegral/queryassetdetail";
		String url=urlConfigUtil.getUrlByKey(RedisKey.URLCON_PREFIXX.getKey(), RedisKey.ZCZX_INTEGRAL_QUERY_DETAIL.getKey());;
		if (StringUtil.isNull(url)) {
			log.error("配置资产中心接口为空");
			return JSONObject.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnError(AccountReturn.EC_BP_ASSETHUB_CONFIG_ERROR_URLADDRESS)));
		}
		//调用资产中心
		JSONObject result = JSONObject.parseObject(DebAsetHttpUtil.sendPost(url,headerMap, dataMap,null));

		if(AccountConstant.REPCD_SUCCESS.equals(result.getJSONObject("header").getString("repcd"))
				&&AccountConstant.RESULT_CODE_SUCCESS.equals(result.getJSONObject("data").getString("RESULT_CODE"))){
			log.info("资产中心处理成功");
			JSONObject data = result.getJSONObject("data");
			resultJson.put("TOTRECNUM", data.get("TOTRECNUM"));//总条数
			resultJson.put("PAGCNT", data.get("PAGCNT"));//总页数
			//用户名解码
			JSONArray listJson = JSON.parseArray(data.getString("REC"));
			for (int i=0;i<listJson.size();i++) {
				JSONObject jsonObject = listJson.getJSONObject(i);
				String userName = jsonObject.getString("USER_NAME");
				if(!StringUtil.isNull(userName)) {
					userName = AtbashUtils.decrypt(userName);
					jsonObject.put("USER_NAME", userName);
					log.info("+++++++++++++++++++"+userName);
				}

			}
			data.put("REC", listJson);
			if(Integer.parseInt(json.getString("PAGE_INDEX"))<=Integer.parseInt(data.getString("PAGCNT"))){
				resultJson.put("RESULT_LIST", data.get("REC"));//明细
				resultJson.put("RECNUM", data.get("RECNUM"));//当前页码条数
			}else{
				resultJson.put("RESULT_LIST", null);//明细
				resultJson.put("RECNUM", "0");//当前页码条数
			}
			return ResultModel.ReturnSucceedJson(resultJson);
		}else{
			log.info("资产中心处理失败："+result.getJSONObject("header").getString("repmsg"));
			resultJson.put("rcode", "-1");
			resultJson.put("message", result.getJSONObject("header").getString("repmsg"));
			return resultJson;
		}
	}


	/**
	 * 调用资产中心变更积分接口(同时积分变动数据记录)
	 * @param json
	 * @param flag
	 * @return
	 */
	private JSONObject modifyIntegral(JSONObject json,String flag){
		JSONObject resultJson=new JSONObject();
		String uuid=UUIDUtil.getUUID();
		//拼接请求参数
		//header头部
		Map<String, String> headerMap=new HashMap<String, String>();
		headerMap.put("IP",json.getString("IP"));
		//		headerMap.put("CHANNEL_RESOURCE",json.getString("CHANNEL_NO"));//渠道编码
		headerMap.put("CHANNEL_RESOURCE","5");//渠道编码
		headerMap.put("USER_NAME",json.getString("USER_NAME"));//
		//data
		Map<String, String> dataMap=new HashMap<String, String>();
		dataMap.put("ASSET_TYPE", AccountConstant.ASSET_TYPE);//01充值卡02卡券03 积分
		dataMap.put("REQUEST_ID",json.getString("BUSINESS_ID"));
		dataMap.put("REQUEST_TIME", TimeUtil.getDate("yyyyMMddHHmmssSSS"));
		dataMap.put("UNIONID",json.getString("LOGIN_ACCOUNT_ID"));//账户ID
		dataMap.put("AMT_DIRECTION",flag);//业务方向-入
		dataMap.put("STATUS", "02");
		dataMap.put("USER_NAME",json.getString("USER_NAME"));
		String acctDate=json.getString("ACCT_DATE");
		dataMap.put("ASS_DATE",StringUtil.isNull(acctDate)?TimeUtil.getDate("YYYYMMdd"):acctDate);//账务日期
		String resultMsg="";

		if(AccountConstant.AMT_DIRECTION_IN.equals(flag)){
			dataMap.put("BUSS_TYPE",json.getString("SOURCE_DESCRIBE"));//来源说明
			dataMap.put("INTEGRAL",json.getBigDecimal("INCOME_NUM")+"");//收入分值
			resultMsg="积分增加成功";
		}else{
			dataMap.put("BUSS_TYPE",json.getString("EXPENDITURE_DESCRIBE"));//支出备注
			dataMap.put("INTEGRAL",json.getBigDecimal("EXPENDITURE_NUM")+"");//支出分值
			resultMsg="积分扣减成功";
		}
		dataMap.put("SIGN_DATA", json.getString("LOGIN_ACCOUNT_ID")+"|"+AccountConstant.ASSET_TYPE+"|"+json.getString("CHANNEL_RESOURCE"));
		//获取接口地址
		String url=urlConfigUtil.getUrlByKey(RedisKey.URLCON_PREFIXX.getKey(), RedisKey.ZCZX_INTEGRAL_ADD.getKey());
		//		String url ="http://10.1.20.30:8082/assetcontroller/rest/userintegral/modifyintegralvalue";
		if (StringUtil.isNull(url)) {
			log.error("配置资产中心接口为空");
			resultJson.put("resultCode", AccountConstant.RESULT_CODE_FAIL);
			resultJson.put("resultMsg", "配置资产中心接口为空");
			return resultJson;
		}
		//调用资产中心
		try {
			JSONObject result = JSONObject.parseObject(DebAsetHttpUtil.sendPost(url,headerMap, dataMap,null));

			JSONObject resHeader=result.getJSONObject("header");
			JSONObject resData=result.getJSONObject("data");
			if(AccountConstant.REPCD_SUCCESS.equals(resHeader.getString("repcd"))
					&&AccountConstant.RESULT_CODE_SUCCESS.equals(resData.getString("RESULT_CODE"))){
				log.info("资产中心处理成功");
				resultJson.put("resultCode",AccountConstant.ASSETHTB_STATUS_SUCCESS);
				resultJson.put("resultMsg", resultMsg);
			}else{
				String msg=AccountConstant.REPCD_SUCCESS.equals(resHeader.getString("repcd"))?resData.getString("RESULT_MESSAGE"):resHeader.getString("repmsg");
				log.info("资产中心处理失败："+msg);
				resultJson.put("resultCode", AccountConstant.ASSETHTB_STATUS_FAIL);
				resultJson.put("resultMsg", msg);
			}
			return resultJson;
		} catch (Exception e) {
			log.info("资产中心接口处理异常："+e.getMessage());
			// TODO: handle exception
		}
		log.error("资产中心接口异常");
		resultJson.put("resultCode", AccountConstant.RESULT_CODE_FAIL);
		resultJson.put("resultMsg", "资产中心接口异常");
		return resultJson;
	}
	/**
	 * 内外网强隔离方式调用
	 * @param json
	 * @return
	 */
	public JSONObject invokeQuery(JSONObject json) {
		return json;

	}
	//	/**
	//	 * 积分变更记录数据操作
	//	 * @param json
	//	 * @param flag
	//	 * @return
	//	 */
	//	private JSONObject modAssethubIntegral(String IntegralType,String AssethubDesc,String uuid,BigDecimal INCOME_NUM){
	//		//入库（积分划转 变更记录）
	//		EcBpAssethubIntegral ecBpAssethubIntegral = new EcBpAssethubIntegral();
	//		ecBpAssethubIntegral.setIntegralType(AccountConstant.INTEGRAL_ADD);
	//		ecBpAssethubIntegral.setId(uuid);
	//		ecBpAssethubIntegral.setAssethubDesc("积分划转记录");
	//		ecBpAssethubIntegral.setAssethubStatus("03");
	//		ecBpAssethubIntegral.setUnionid(json.getString("LOGIN_ACCOUNT_ID"));
	//		ecBpAssethubIntegral.setAssetType(AccountConstant.ASSET_TYPE);
	//		ecBpAssethubIntegral.setIntegral(json.getBigDecimal("INCOME_NUM"));
	//		ecBpAssethubIntegral.setCreateTime(new Date());
	//		return json;
	//	}
}
